jdautel
08-15-2016, 09:31 AM
Ok, so I'm really new to VBA (about 3 weeks). And am just coding something simple to make a task easier here in the office. For some reason I'm running into a problem with my code though. Here's the code:
Sub callargument(x As Double)
Dim range1 As Range
Dim range2 As Range
Set range1 = Range("A55:A150")
Dim cell As Object
Dim cell2 As Object
Set range2 = Range("B1:B52")
Dim currentcell As Range
'Now I search in range 1 for whatever value it is that I need using a for loop
For Each cell In range1
If cell.Value = x Then
'if value is found then I want to bold the value name (hence the offset) in the above range 2
For Each cell2 In range2
If cell.Value = x Then
'searches for value
Set currentcell = Range(cell.Address)
currentcell.Select
Selection.Offset(-1, 0).Font.Bold = True
'this should bold the value of the cell to the left of the selected cell in the B range
End If
Next
End If
Next
End Sub
For some reason it is bolding the cells in range1 rather than range2 and I don't know why it would be doing that. Sorry if this is a really simple question but I've been playing with it for about 30 minutes and am at a loss..
Sub callargument(x As Double)
Dim range1 As Range
Dim range2 As Range
Set range1 = Range("A55:A150")
Dim cell As Object
Dim cell2 As Object
Set range2 = Range("B1:B52")
Dim currentcell As Range
'Now I search in range 1 for whatever value it is that I need using a for loop
For Each cell In range1
If cell.Value = x Then
'if value is found then I want to bold the value name (hence the offset) in the above range 2
For Each cell2 In range2
If cell.Value = x Then
'searches for value
Set currentcell = Range(cell.Address)
currentcell.Select
Selection.Offset(-1, 0).Font.Bold = True
'this should bold the value of the cell to the left of the selected cell in the B range
End If
Next
End If
Next
End Sub
For some reason it is bolding the cells in range1 rather than range2 and I don't know why it would be doing that. Sorry if this is a really simple question but I've been playing with it for about 30 minutes and am at a loss..