ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Need code for simple IF-Then (https://www.excelbanter.com/excel-programming/345089-need-code-simple-if-then.html)

excelnut1954

Need code for simple IF-Then
 
I'm trying to insert an "X" in any empty cells in Row 7 for columns C,D
E & F. I'm formatting all the cells in a large block (columns A - R,
with a varied number of rows), but the results using CurrentRegion
won't extend out past columns C - F when they are empty, which they
usually are. I could include a macro to insert the X's, but sometimes
these columns actually DO have data in them, and I don't want to
overwrite any data. THANKS


Leith Ross[_249_]

Need code for simple IF-Then
 

Hello excelnut1954,

Here is simple macro to fill in the empty spaces. Copy and Paste this
code into a VBA project module.


Code:
--------------------
Public Sub XFill()
Dim C As Long

For C = 3 to 6
If Cells(7, C).Value < "" Then
Cells(7, C).Value = "X"
End If
Next C

End Sub

--------------------

Sincerely,
Leith Ross


--
Leith Ross
------------------------------------------------------------------------
Leith Ross's Profile: http://www.excelforum.com/member.php...o&userid=18465
View this thread: http://www.excelforum.com/showthread...hreadid=483342


Leith Ross[_250_]

Need code for simple IF-Then
 

Hello excelnut1954,

Here is simple macro to fill in the empty spaces. Copy and Paste this
code into a VBA project module.


Code:
--------------------
Public Sub XFill()
Dim C As Long

For C = 3 to 6
If Cells(7, C).Value = "" Then
Cells(7, C).Value = "X"
End If
Next C

End Sub

--------------------

Sincerely,
Leith Ross


--
Leith Ross
------------------------------------------------------------------------
Leith Ross's Profile: http://www.excelforum.com/member.php...o&userid=18465
View this thread: http://www.excelforum.com/showthread...hreadid=483342


excelnut1954

Need code for simple IF-Then
 
Excellent!!! I really appreaciate this. I've taken an in-house class
on VBA where I work, but of course, that was just the start. I got an
800+ page book on VBA, but it barely touches on the If-then coding.
I've learned alot just playing around with everything, so I can do
quite alot now. But, I really needed this to complete a project of
automating a spreadsheet I designed here before, so others can update
daily info without being an expert in Excel.
Thanks for getting me over this hurdle, and for the quick response.


Dana DeLouis[_3_]

Need code for simple IF-Then
 
Hi. Just another option:

On Error Resume Next
[C7:F7].SpecialCells(xlCellTypeBlanks) = "X"

HTH
--
Dana DeLouis
Win XP & Office 2003


"excelnut1954" wrote in message
oups.com...
Excellent!!! I really appreaciate this. I've taken an in-house class
on VBA where I work, but of course, that was just the start. I got an
800+ page book on VBA, but it barely touches on the If-then coding.
I've learned alot just playing around with everything, so I can do
quite alot now. But, I really needed this to complete a project of
automating a spreadsheet I designed here before, so others can update
daily info without being an expert in Excel.
Thanks for getting me over this hurdle, and for the quick response.




excelnut1954

Need code for simple IF-Then
 
Thanks Dana. I'll have to check and see how this works different than
what Leith gave me earlier. They both seem to work for that I'm doing
in this project.
Thanks again.



All times are GMT +1. The time now is 03:04 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com