|
-
Sep 8th, 2005, 10:11 AM
#1
Thread Starter
Addicted Member
Need help! Excel & VBA trouble
Hi there.
I need VBA to compare several cells in Excel. It's rather difficault to explain the situation, but I'll try it.
Here's is the spreadsheet (| | represent a single cell):
| 0466-1-1-1-1 | 01 | - | 01 | - | 01 | - | 01 |
| 0466-1-1+1 | 01 | - | 01 | + | 01 |
| 0466-1-1 | 01 | - | 01 |
The first one is correct, the other 2 are wrong, while e.g.
| 0466-1-3+1 | 01 | - | 03 | + | 01 |
is correct.
Here's my code:
VB Code:
Sub chk()
Dim iCompare As Long
Dim iCheck As Long
Dim XL As Variant
Dim xlWS As Variant
Dim Checksum As Variant
Dim Compare As Variant
Dim Value_chk As Integer
Dim Kolonne As Variant
Set xlWS = Sheet3
iCompare = 3
iCheck = 2
Value_chk = 3
Kolonne = 7
Columns(Value_chk).Interior.Color = RGB(255, 255, 255)
Do While xlWS.Cells(iCheck, Value_chk).Value <> ""
Do While xlWS.Cells(iCompare, Value_chk).Value <> ""
Checksum = Cells(iCheck, Kolonne).Value
Compare = Cells(iCompare, Kolonne).Value
If Checksum = Compare Then
GoTo Hvid
GoTo Ring
End If
Hvad:
If Checksum <> Compare Then
GoTo Her
Else: GoTo Hvid
End If
Her:
If Kolonne <= 19 Then
With Cells(iCheck, 3).Interior
.Color = RGB(255, 0, 0)
End With
With Cells(iCompare, 3).Interior
.Color = RGB(255, 0, 0)
End With
Else
GoTo Ring
End If
Hvid:
iCompare = iCompare + 1
Ring:
Loop
iCompare = iCheck + 2
iCheck = iCheck + 1
Loop
With Columns(Value_chk).Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Columns(Value_chk).Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Columns(Value_chk).Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Columns(Value_chk).Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Columns(Value_chk).Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
End Sub
Hope you understand me 
Edit: Fixed [/vbcode] end tag. - Hack
Last edited by Hack; Sep 8th, 2005 at 10:16 AM.
-
Sep 8th, 2005, 10:16 AM
#2
Re: Need help! Excel & VBA trouble
Moved to Office Development
-
Sep 8th, 2005, 11:11 AM
#3
Re: Need help! Excel & VBA trouble
A couple of things,
Dont use GoTos they are not very good to use and makes your code hard to read.
What is it that your trying to compare? Are you just looking for blank cells?
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Sep 8th, 2005, 11:22 AM
#4
Thread Starter
Addicted Member
Re: Need help! Excel & VBA trouble
I can't use anything else.
It's hard to explain. Any numbers that are shorter and contain the same numbers than e.g. 0466-1-1-1-1-1+1 are wrong, while a number such as 0466-1-3 is correct. Every number is seperated into their own cells.
-
Sep 8th, 2005, 12:00 PM
#5
Re: Need help! Excel & VBA trouble
So this is one row...
Code:
A | B | C | D | E | F | G
---------------------------
0466 | 1 | 1 | 1 | 1 | 1 | 1
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Sep 8th, 2005, 03:47 PM
#6
Thread Starter
Addicted Member
Re: Need help! Excel & VBA trouble
Exactly - well, almost...there is a "-" between all numbers, except for the last two - there's a "+" that seperates them
-
Sep 8th, 2005, 05:28 PM
#7
Re: Need help! Excel & VBA trouble
Ok, but can you explain why they are wrong? It will make it easier to try to come up with some code for.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Sep 9th, 2005, 02:48 AM
#8
Re: Need help! Excel & VBA trouble
uh not sure what you mean .... but try:
Code:
=concatenate("0466-",<cellref>,<cellref>,<cellref>)
Or do you mean that your code has to split the first complete one, remove all the first digits to the '-' then shove all other elements (numbers and -/+ signs) into separate cells?
(if so then your first example you have said that the second two lines of is wrong, it isn't)
Feeling like a fly on the inside of a closed window (Thunk!)
If I post a lot, it is because I am bored at work! ;D Or stuck...
* Anything I post can be only my opinion. Advice etc is up to you to persue...
-
Sep 11th, 2005, 04:19 PM
#9
Thread Starter
Addicted Member
Re: Need help! Excel & VBA trouble
I was right that it was hard to explain This is the situation:
| A | B | C | D | E | F | G | H | I | J | K | L | M
---------------------------
0466 | - | 1 | - | 1 | - | 1 | - | 1 | - | 1 | + | 1
0466 | - | 1 | - | 1 |
0466 | - | 1 | | | | | | | | | + | 1
0466 | - | 1 | - | 3 |
Now, row no 1 is correct.
Row no 2 has the same numbers, but is too short - therefore it's wrong.
Same with row no 3, although it has a '+' instead af a '-'.
Row no 4 is correct, because at least one of it's numbers is different from the other rows
-
Sep 13th, 2005, 07:47 AM
#10
Thread Starter
Addicted Member
Re: Need help! Excel & VBA trouble
Is it confusing, or is the solution complicated? :S
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|