AGrayson84
New Member
- Joined
- Mar 21, 2017
- Messages
- 18
Hi everyone, I'm working on a final piece to my puzzle, for now, and that is to certain data from cells in one worksheet to format another worksheet for a CSV file that will be used for creating DHCP reservations.
What I'd like is to export only data from my worksheet called, "DHCP", that doesn't contain "null" in the the cells. Only columns A thru H are being used, and rows 1 thru 200. Each row may vary-- any given row may end up containing either the word "null" across all 8 columns, or all 8 cells in each row will contain other text that is not equal to "null". The word "null" is either all the way across each row, or it doesn't exist in a row at all-- a cell containing the word "null" is never mixed in a row with other cells that don't contain the word "null".
More specifically, I would like any row that contains the word "null" to just be completely ignored on the export file. I'm trying to avoid having 7 commas side-by-side in the export file, for each row that contained Null. Here is an example of the data I'm working with, and how I'd like the CSV to end up looking:
Data before exported to CSV:
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]
[/TD]
[TD]A[/TD]
[TD]B[/TD]
[TD]C[/TD]
[TD]D[/TD]
[TD]E[/TD]
[TD]F[/TD]
[TD]G[/TD]
[TD]H[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]null[/TD]
[TD]null[/TD]
[TD]null[/TD]
[TD]null[/TD]
[TD]null[/TD]
[TD]null[/TD]
[TD]null[/TD]
[TD]null[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]Apple[/TD]
[TD]Banana[/TD]
[TD]Orange[/TD]
[TD]Grape[/TD]
[TD]Watermelon[/TD]
[TD]Cantaloupe[/TD]
[TD]Strawberry[/TD]
[TD]Cherry[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]null[/TD]
[TD]null[/TD]
[TD]null[/TD]
[TD]null[/TD]
[TD]null[/TD]
[TD]null[/TD]
[TD]null[/TD]
[TD]null[/TD]
[/TR]
</tbody>[/TABLE]
Data after exported to CSV (viewed in Excel):
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]
[/TD]
[TD]A[/TD]
[TD]B[/TD]
[TD]C[/TD]
[TD]D[/TD]
[TD]E[/TD]
[TD]F[/TD]
[TD]G[/TD]
[TD]H[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]Apple[/TD]
[TD]Banana[/TD]
[TD]Orange[/TD]
[TD]Grape[/TD]
[TD]Watermelon[/TD]
[TD]Cantaloupe[/TD]
[TD]Strawberry[/TD]
[TD]Cherry[/TD]
[/TR]
</tbody>[/TABLE]
Data after exported to CSV (viewed In Notepad):
Apple,Banana,Orange,Grape,Watermelon,Cantaloupe,Strawberry,Cherry
Here is a simple export-to-CSV VBA script that I think I could use, I just can't figure out how to right the IF statement so that it does nothing with the rows that contain the word "null":
If someone wouldn't mind helping out with this I'd very greatly appreciate it! I have a whole slew of other VBA scripts doing various things and this is the last thing that I have been having a hard time with and can't seem to find any similar requests on anywhere else on the Internet. Thanks everyone!
-Andrew
What I'd like is to export only data from my worksheet called, "DHCP", that doesn't contain "null" in the the cells. Only columns A thru H are being used, and rows 1 thru 200. Each row may vary-- any given row may end up containing either the word "null" across all 8 columns, or all 8 cells in each row will contain other text that is not equal to "null". The word "null" is either all the way across each row, or it doesn't exist in a row at all-- a cell containing the word "null" is never mixed in a row with other cells that don't contain the word "null".
More specifically, I would like any row that contains the word "null" to just be completely ignored on the export file. I'm trying to avoid having 7 commas side-by-side in the export file, for each row that contained Null. Here is an example of the data I'm working with, and how I'd like the CSV to end up looking:
Data before exported to CSV:
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]
[/TD]
[TD]A[/TD]
[TD]B[/TD]
[TD]C[/TD]
[TD]D[/TD]
[TD]E[/TD]
[TD]F[/TD]
[TD]G[/TD]
[TD]H[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]null[/TD]
[TD]null[/TD]
[TD]null[/TD]
[TD]null[/TD]
[TD]null[/TD]
[TD]null[/TD]
[TD]null[/TD]
[TD]null[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]Apple[/TD]
[TD]Banana[/TD]
[TD]Orange[/TD]
[TD]Grape[/TD]
[TD]Watermelon[/TD]
[TD]Cantaloupe[/TD]
[TD]Strawberry[/TD]
[TD]Cherry[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]null[/TD]
[TD]null[/TD]
[TD]null[/TD]
[TD]null[/TD]
[TD]null[/TD]
[TD]null[/TD]
[TD]null[/TD]
[TD]null[/TD]
[/TR]
</tbody>[/TABLE]
Data after exported to CSV (viewed in Excel):
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]
[/TD]
[TD]A[/TD]
[TD]B[/TD]
[TD]C[/TD]
[TD]D[/TD]
[TD]E[/TD]
[TD]F[/TD]
[TD]G[/TD]
[TD]H[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]Apple[/TD]
[TD]Banana[/TD]
[TD]Orange[/TD]
[TD]Grape[/TD]
[TD]Watermelon[/TD]
[TD]Cantaloupe[/TD]
[TD]Strawberry[/TD]
[TD]Cherry[/TD]
[/TR]
</tbody>[/TABLE]
Data after exported to CSV (viewed In Notepad):
Apple,Banana,Orange,Grape,Watermelon,Cantaloupe,Strawberry,Cherry
Here is a simple export-to-CSV VBA script that I think I could use, I just can't figure out how to right the IF statement so that it does nothing with the rows that contain the word "null":
Code:
Dim ColNum As Integer
Dim Line As String
Dim LineValues() As Variant
Dim OutputFileNum As Integer
Dim PathName As String
Dim RowNum As Integer
Dim SheetValues() As Variant
PathName = Application.ActiveWorkbook.Path
OutputFileNum = FreeFile
Open PathName & "\Test.csv" For Output Lock Write As #OutputFileNum
SheetValues = Sheets("DHCP").Range("A1:H200").Value
ReDim LineValues(1 To 8)
For RowNum = 1 To 200
For ColNum = 1 To 8
LineValues(ColNum) = SheetValues(RowNum, ColNum)
Next
Line = Join(LineValues, ",")
Print #OutputFileNum, Line
End If
Next
Close OutputFileNum
If someone wouldn't mind helping out with this I'd very greatly appreciate it! I have a whole slew of other VBA scripts doing various things and this is the last thing that I have been having a hard time with and can't seem to find any similar requests on anywhere else on the Internet. Thanks everyone!
-Andrew