Code to ignore blank or blank contains space only

dubiousp

New Member
Joined
Aug 12, 2015
Messages
32
Good morning my code is set to ignore blanks and move on which seems to work well, the problem occurs when the cell contains a space it trys to work with it.. I have attached code below so far any thoughts appreciated



Sub GI()

Dim row As Integer

Dim column As Integer
Dim ws1 As Worksheet
Dim ws2 As Worksheet
Dim wb As Workbook
Dim print_row As Integer
Dim rs1 As Long
Dim re1 As Long
Dim cs1 As Long
Dim ce1 As Long

rs1 = Sheets("data").Range("b1").Value 'row start value set from textboxt
re1 = Sheets("data").Range("b2").Value 'row end value set from textboxt
cs1 = Sheets("data").Range("b3").Value 'col start value set from textboxt
ce1 = Sheets("data").Range("b4").Value 'col end value set from textboxt



Set wb = ThisWorkbook
Set ws1 = wb.Sheets("C&E")
Set ws2 = wb.Sheets("Print")



print_row = 13


ws2.Rows("13:100000").EntireRow.Delete

For row = rs1 To re1


For column = cs1 To ce1


'If IsEmpty(ws1.Cells(row, column).Value) = True Then
'Do nothing
If IsEmpty(ws1.Cells(row, column).Value) = True Then
'Do nothing
ElseIf IsNumeric(ws1.Cells(row, column).Value) = True Then
If (IsEmpty(ws1.Cells(row, 3).Value) = True Or IsEmpty(ws1.Cells(15, column).Value) = True) Then
'Do nothing
Else
ws2.Cells(print_row, 1).Value = ws1.Cells(row, 3).Value
ws2.Cells(print_row, 2).Value = ws1.Cells(15, column).Value
ws2.Cells(print_row, 3).Value = ws1.Cells(row, column).Value
print_row = print_row + 1
End If
ElseIf ws1.Cells(row, column).Value = ws1.Cells(17, 2).Value Then
If (IsEmpty(ws1.Cells(row, 3).Value) = True Or IsEmpty(ws1.Cells(15, column).Value) = True) Then
'Do nothing
Else
ws2.Cells(print_row, 1).Value = ws1.Cells(row, 3).Value
ws2.Cells(print_row, 2).Value = ws1.Cells(15, column).Value
ws2.Cells(print_row, 3).Value = "0"
print_row = print_row + 1
End If
End If
Next column
If IsEmpty(ws1.Cells(row, 3).Value) = True Then
'Do nothing
Else
print_row = print_row
End If
Next row

End Sub
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Use the Trim function to remove spaces before checking whether the cell is blank. You appear to have a lot of code lines checking for blank cells, but here's one example. You can then apply similar changes to the others.

This line:
Code:
If IsEmpty(ws1.Cells(row, 3).Value) = True Then
becomes:
Code:
If IsEmpty(Trim(ws1.Cells(row, 3).Value)) = True Then
 
Upvote 0
You can use special cells to loop through a range of numbers.
For example:
Below will just select numbers, use the example to just loop through numbers.
VBA Code:
Sub selectNum()
    Dim rng As Range
    Set rng = Columns("A:A").SpecialCells(xlCellTypeConstants, 1)
    rng.Select    ' or what ever you want to do with it.
End Sub
 
Upvote 0
Are you saying that you also want to ignore the cell if it contains text that is formatted as strike through? Not sure what you mean by "in column not row"?

If so, the code example is now:
Code:
If IsEmpty(Trim(ws1.Cells(row, 3).Value)) = True Or ws1.Cells(row, 3).Font.Strikethrough = True Then
 
Upvote 0
Brill, I have attached a PDF of Column


Sub GI()

Dim row As Integer

Dim column As Integer
Dim ws1 As Worksheet
Dim ws2 As Worksheet
Dim wb As Workbook
Dim print_row As Integer
Dim rs1 As Long
Dim re1 As Long
Dim cs1 As Long
Dim ce1 As Long

rs1 = Sheets("data").Range("b1").Value 'row start value set from textboxt
re1 = Sheets("data").Range("b2").Value 'row end value set from textboxt
cs1 = Sheets("data").Range("b3").Value 'col start value set from textboxt
ce1 = Sheets("data").Range("b4").Value 'col end value set from textboxt



Set wb = ThisWorkbook
Set ws1 = wb.Sheets("C&E")
Set ws2 = wb.Sheets("Print")



print_row = 13


ws2.Rows("13:100000").EntireRow.Delete

For row = rs1 To re1


For column = cs1 To ce1


'If IsEmpty(ws1.Cells(row, column).Value) = True Then
'Do nothing
If IsEmpty(ws1.Cells(row, column).Value) = True Then
'Do nothing
ElseIf IsNumeric(ws1.Cells(row, column).Value) = True Then
If (IsEmpty(ws1.Cells(row, 3).Value) = True Or IsEmpty(ws1.Cells(15, column).Value) = True) Then
'Do nothing
Else
ws2.Cells(print_row, 1).Value = ws1.Cells(row, 3).Value
ws2.Cells(print_row, 2).Value = ws1.Cells(15, column).Value
ws2.Cells(print_row, 3).Value = ws1.Cells(row, column).Value
print_row = print_row + 1
End If
ElseIf ws1.Cells(row, column).Value = ws1.Cells(17, 2).Value Then
If (IsEmpty(ws1.Cells(row, 3).Value) = True Or IsEmpty(ws1.Cells(15, column).Value) = True) Then
'Do nothing
Else
ws2.Cells(print_row, 1).Value = ws1.Cells(row, 3).Value
ws2.Cells(print_row, 2).Value = ws1.Cells(15, column).Value
ws2.Cells(print_row, 3).Value = "0"
print_row = print_row + 1
End If
End If

Next column
'If IsEmpty(ws1.Cells(row, 3).Value) = True Then
'If IsEmpty(Trim(ws1.Cells(row, 3).Value)) = True Then 'ignore row with blank and space only
If IsEmpty(Trim(ws1.Cells(row, 3).Value)) = True Or ws1.Cells(row, 3).Font.Strikethrough = True Then
'Do nothing
Else
print_row = print_row
End If

Next row
 

Attachments

  • Document1.png
    Document1.png
    82.3 KB · Views: 5
Upvote 0

Forum statistics

Threads
1,214,638
Messages
6,120,674
Members
448,977
Latest member
moonlight6

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