First, with a little searching and some Google-Fu. I have pieced together a working Excel spreadsheet with some VBA. I am by no means a coder, nor is it my profession, however, it is something I have a basic understanding of. That said, I have been banging my head against a wall.
I am pulling data from a website into sheet1 in Excel, copying it to sheet2 while cleaning up the data a bit, copying it a second time to sheet3 to further isolate the information I need. (I know it's an overly complicated process but, by doing it in steps I have a better understanding of what is going on and it helps me learn).
First step, copy mined website data into sheet2:
Sub DataReOrganizer()
Dim s1 As Worksheet, s2 As Worksheet
Dim Cook As Long, i As Long, K As Long, v As String
On Error Resume Next
Set s1 = Sheets("Sheet1")
Set s2 = Sheets("Sheet2")
Cook = s1.Cells(Rows.Count, "A").End(xlUp).Row
K = 2
For i = 1 To Cook
v = s1.Cells(i, "A").Text
If v = "Contact Information" Then
K = K + 1
Else
ary = Split(v, ": ")
If ary(0) = "Name" Then s2.Cells(K, 1) = ary(1)
If ary(0) = "License" Then s2.Cells(K, 2) = ary(1)
If ary(0) = "License Status" Then s2.Cells(K, 3) = ary(1)
If ary(0) = "City/State" Then s2.Cells(K, 4) = ary(1)
If ary(0) = "County" Then s2.Cells(K, 5) = ary(1)
If ary(0) = "Home Phone" Then s2.Cells(K, 6) = ary(1)
If ary(0) = "Work Phone" Then s2.Cells(K, 7) = ary(1)
If ary(0) = "Cell Phone" Then s2.Cells(K, 8) = ary(1)
If ary(0) = "Email Address" Then s2.Cells(K, 9) = ary(1)
If ary(0) = "Region" Then s2.Cells(K, 10) = ary(1)
If ary(0) = "Ever Been Disciplined?" Then s2.Cells(K, 11) = ary(1)
If ary(0) = "Note" Then s2.Cells(K, 12) = ary(1)
End If
Next I
End Sub
Now that the information is no longer one big lumpy mass in column A, I move to step 2: The information is now copied into sheet3 using formulas in each column (A - N) ex:
=IFERROR(SUBSTITUTE(LEFT(Sheet2!$A2,SEARCH(", ",Sheet2!$A2)),",",""),"")
The formulas go to row 1500 in each column, this is done to keep the varying amount of data pulled from the website in sheet3 always organized. I may only have 600 or so rows of data, while the remaining cells, up to 1500, are blank.
This is where I am stuck. I can copy the values (minus the formulas) to sheet4. However, it copies the populated values AND the 900 or so rows of cells that have no calculated values from the formulas. I have searched and found various code to remove empty cells, but they are not working, or I am not able to figure out how to tweak them to my use. No matter what code I use to copy, it always returns 1500 rows, with only 600 or so populated. Am I missing something? I have even tried copying the newly created sheet with only the values, that still returns 1500 lines.
***Edited to add the code I am currently using for testing purposes:
Sub Test_Copy()
Worksheets("Sheet3").Range("A:N").Copy
Worksheets("Sheet4").Range("A:N").PasteSpecial Paste:=xlPasteValues
Application.CutCopyMode = False
End Sub
I found another question with some code that copies each cell, one at a time, but that is terribly slow.
Excel macro - paste only non empty cells from one sheet to another
Plus, I get the impression from responses, this is not a good idea, or best practice.