It's been a minute - help needed writing an If-Then statement

zombiemaster

Board Regular
Joined
Oct 27, 2009
Messages
241
Hi, All... I haven't been around VBA much the past couple of years, and I'm pretty rusty at this point. Hoping this is an easy answer to get to...

What I have right now is a workbook with multiple sheets: one for each month, then a "Print Sheet" and a "Cover Sheet". My existing code takes the contents of two cells (D9 & D11) from the current row on the Print Sheet and drops that data into two corresponding cells on the Cover Sheet so that page can be printed (which is also done through the code), then those cells clear out until the next time I run the code.

Example:
Sheets("CoverSheet").Range("D9") = .Cells(, 5).Text
Sheets("CoverSheet").Range("D11") = .Cells(, 6).Text

What I need now is this: I have a cell (in the 5th column) in the Print Sheet that can have two different types of values: one that starts with the letter "L" and the other that is numeric-only. If the value is the "L" type, I want my code to put an "X" in cell B5 on the Cover Sheet, and if it's the numeric type, I want the "X" in cell B7.

I'm sure this is just an "if-then" type of situation but as I said, it's been a minute and I'm not sure how to do it.

What I need is something to the effect of:

If the text in the 5th column begins with "L", put an "X" in Sheets(CoverSheet").Range("B5")
If the text in the 5th column begins with a number, put an "X" in Sheets(CoverSheet").Range("B7")

I just don't know how to write that so it works!

Thanks for any help!
-=ZM=-
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Not clear to me.

What row, 9? 11? Something else? 5th column is E?
Yes column 5 is E. I stated it as 5 because that's how the current syntax is in the code I already have listed: " .Cells(, 5).Text" Sorry if that confused you.

As for which row, are you asking which row the "X" should be placed on, in the CoverSheet tab? If that's your question, then the answer is this:

If the text in column E on the PrintSheet begins with "L", put an "X" in cell B5 on the CoverSheet tab
If the text in column E on the PrintSheet begins with a number, put an "X" in cell B5 on the CoverSheet tab

Thanks for looking!
-=ZM=-
 
Upvote 0
Sorry, still doesn't tell me what row you're concerned with in column E of PrintSheet. You want to look at the entire E range that has data, such as from E1 to Exxx looking for values that begin with a capital L? Or just one cell? Trying to figure out what row this statement refers to
I have a cell (in the 5th column)

And this doesn't seem possible to me
My existing code takes the contents of two cells (D9 & D11) from the current row
because the current row cannot be both 9 and 11, but if you don't have any issues with how that works then don't mind me.
 
Upvote 0
Sorry, still doesn't tell me what row you're concerned with in column E of PrintSheet. You want to look at the entire E range that has data, such as from E1 to Exxx looking for values that begin with a capital L? Or just one cell? Trying to figure out what row this statement refers to


And this doesn't seem possible to me

because the current row cannot be both 9 and 11, but if you don't have any issues with how that works then don't mind me.
Ok, now I see what you mean. Sorry for the confusion!

So, the code I use uses the current row that the cursor is on to do all the stuff I need to do. So if I'm on row 2 in the Print Sheet, that's the starting point for everything after that. That's what this piece does, is it places the contents of the Print Sheet current row, whatever is in column E and F, into D9 and D11 on the Cover Sheet:

Sheets("CoverSheet").Range("D9") = .Cells(, 5).Text
Sheets("CoverSheet").Range("D11") = .Cells(, 6).Text

It's just the variable of what is in column E that could be either an "L" or all numbers that is confusing me, how to put that "X" on the Cover Sheet in either B5 or B7.

I hope that helps, thanks for the assistance.
-=ZM=-
 
Upvote 0
I have to imagine that this is as simple as
VBA Code:
If UCase(Left(.Cells(, 5).Text,1)="L")) Then
   Sheets("CoverSheet").Range("D9") = .Cells(, 5).Text
   Sheets("CoverSheet").Range("D11") = .Cells(, 6).Text
End If
assuming you want the same result if "L" or "l" (lower case l).
HTH

If I may suggest, next time post what you have vs what you want. It might eliminate much of the questioning you'll get.

EDIT - maybe close, but not quite right. I'll probably run out of time to edit this post so please wait for another suggestion.
 
Upvote 0
One way:
VBA Code:
If UCase(Left(.Cells(, 5).Text,1)="L")) Then Sheets("CoverSheet").Range("B5") = "X"
If IsNumeric(.Cells(,5)) Then Sheets("CoverSheet").Range("B7") = "X"
or
VBA Code:
If UCase(Left(.Cells(, 5).Text, 1)) = "L" Then
   Sheets("CoverSheet").Range("B5") = "X"
ElseIf IsNumeric(.Cells(, 5)) Then
   Sheets("CoverSheet").Range("B7") = "X"
End If
 
Upvote 0

Forum statistics

Threads
1,214,833
Messages
6,121,857
Members
449,051
Latest member
excelquestion515

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