ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Test for null - insert a row if isnull (https://www.excelbanter.com/excel-discussion-misc-queries/149653-test-null-insert-row-if-isnull.html)

Bonnie

Test for null - insert a row if isnull
 
Hi,

In a Macro (VBA) I am testing cell A6 for null, if isnull (""), I want to
insert a row. The problem is that it always inserts a row even when cell A6
has something in it? There are blank spaces at the from of the cell so I
trimmed it. Does anyone see something I'm doing wrong?


Sheets("Sheet1").Select
Range("A6").Select
If Trim(A6) = "" Then
Range("A4").Select
Selection.EntireRow.Insert
End If

Thanks in advance.

Bonnie

Toppers

Test for null - insert a row if isnull
 
Should be ....

Trim(Range("A6"))

"Bonnie" wrote:

Hi,

In a Macro (VBA) I am testing cell A6 for null, if isnull (""), I want to
insert a row. The problem is that it always inserts a row even when cell A6
has something in it? There are blank spaces at the from of the cell so I
trimmed it. Does anyone see something I'm doing wrong?


Sheets("Sheet1").Select
Range("A6").Select
If Trim(A6) = "" Then
Range("A4").Select
Selection.EntireRow.Insert
End If

Thanks in advance.

Bonnie


Ron de Bruin

Test for null - insert a row if isnull
 
Use it like this

This line is wrong
If Trim(A6) = "" Then



Sub Test()
Sheets("Sheet1").Select

If Trim(Range("A6")) = "" Then
Range("A4").EntireRow.Insert
End If
End Sub


--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"Bonnie" wrote in message ...
Hi,

In a Macro (VBA) I am testing cell A6 for null, if isnull (""), I want to
insert a row. The problem is that it always inserts a row even when cell A6
has something in it? There are blank spaces at the from of the cell so I
trimmed it. Does anyone see something I'm doing wrong?


Sheets("Sheet1").Select
Range("A6").Select
If Trim(A6) = "" Then
Range("A4").Select
Selection.EntireRow.Insert
End If

Thanks in advance.

Bonnie


Bonnie

Test for null - insert a row if isnull
 
Thank you both for responding. I'll give it a try.

"Ron de Bruin" wrote:

Use it like this

This line is wrong
If Trim(A6) = "" Then



Sub Test()
Sheets("Sheet1").Select

If Trim(Range("A6")) = "" Then
Range("A4").EntireRow.Insert
End If
End Sub


--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"Bonnie" wrote in message ...
Hi,

In a Macro (VBA) I am testing cell A6 for null, if isnull (""), I want to
insert a row. The problem is that it always inserts a row even when cell A6
has something in it? There are blank spaces at the from of the cell so I
trimmed it. Does anyone see something I'm doing wrong?


Sheets("Sheet1").Select
Range("A6").Select
If Trim(A6) = "" Then
Range("A4").Select
Selection.EntireRow.Insert
End If

Thanks in advance.

Bonnie




All times are GMT +1. The time now is 01:50 AM.

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