check the first letter of cells in a row

ashwinghanta

Board Regular
Joined
Dec 6, 2011
Messages
118
I want to test if the first letter of the cells in row 394 start with Q in sheet 6.and if so then mark x in those columns in row 552 in sheet 6 I am using the code



Code:
If Left(sh6.Cells(394, j), 1) = "Q" Then
      sh2.Cells(552, j).Value = "x"
      End If

But I get x marked only for the first column of the row 552. Infact I placed Q in the first 20 cells of sh4.row 394. Where is it going wrong?
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Your narrative says both source and destination rows are in sheet 6, but your code uses a different sheet variable for the destination.
Would this fix it?
Code:
If Left(sh6.Cells(394, j).Value, 1) = "Q" Then
      sh6.Cells(552, j).Value = "x"
End If
 
Last edited:
Upvote 0
I mean I get x marked only for the first column of the row 552 on sheet2.

Your narrative says both source and destination rows are in sheet 6, but your code uses a different sheet variable for the destination.
Would this fix it?
Code:
If Left(sh6.Cells(394, j).Value, 1) = "Q" Then
      sh6.Cells(552, j).Value = "x"
End If
 
Upvote 0
Code:
Sub abc()
Set sh2 = Sheets("Testfall-Input_Antrag")
Set sh6 = Sheets("6-PR_Antrag")
For j = 7 To 1000

  If Left(sh6.Cells(394, j), 1) = "Q" Then
  sh2.Cells(552, j).Value = "x"
   End If

If sh6.Cells(1, j) = vbNullString Then
    Exit For
    End If
    Next

End sub
 
Upvote 0
This is your culprit

Code:
f sh6.Cells(1, j) = vbNullString Then
    Exit For
    End If
    Next
Apparently Row 1 of the column H is blank and is ending the procedure. Maybe you meant to use row 394 instead of row 1?
 
Upvote 0

Forum statistics

Threads
1,213,482
Messages
6,113,916
Members
448,533
Latest member
thietbibeboiwasaco

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top