-
Solved: VBA Offset help
I am trying to do the following.
I am copying data from one sheet to another and would like if in column B data starts with "DC" then Column C would be "Desktop" else "Laptop"
I tried the following
[VBA] If Left(Range("B7:B400").Value, 2) = "DC" Then
Range("B7:B400").Offset(0, 1).Value = "Desktop"
Else
Range("B7:B400").Offset(0, 1).Value = "Laptop"
End If[/VBA]
But got an error.
Any help would be great.
-
Try like:
[VBA]Option Explicit
Sub Example()
Range("B1:B25").FormulaArray = "=IF(LEFT(A1:A25,2)=""DC"",""Desktop"",""Laptop"")"
Range("B1:B25").Value = Range("B1:B25").Value
End Sub[/VBA]
-
GTO that works but problem with it is if cell is blank it's putting "Laptop".
Can we have it look at cell if value = "" then don't do anything?
-
Change the formula that we are temporarily plunking in.
[VBA]Range("B1:B25").FormulaArray = "=IF(A1:A25="""","""",IF(LEFT(A1:A25,2)=""DC"",""Desktop"",""Laptop"")) "[/VBA]
-
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