Re: Add Formula to Bottom of Column
Good Stuff guys, thanks for the help.
Re: Add Formula to Bottom of Column
Good Stuff guys, thanks for the help.
Re: Dim As Long Won't Work With One Cell?
I'm trying to determine how long Column "C" is so the code knows how many rows to put the formula in.
Alright, below is the code I'm using. If "C1" is the only cell in column "C" that has info the code freaks out and calulates all the way to the bottom (at least I think so). Does anyone know how to avoid this? Also, column "C" will obviously have different lentghs of data, it won't always just be one. Do I essentially need to have a header of some sort to always have more than one cell with a value in it? What if I don't have any values, other than the header, do I then have to write code to bypass it all together? Sorry if the is too many "ifs".
Re: Extra Row Included At Bottom
You the man Brian Walters, you the man.
I've got the following code for the attached worksheet. My problem lies at the end of the code where I'm trying to determine the length of characters in column A. I get a zero value after the last row with an actual value. Does anyone know what is causing this? I know I can change my code to:
but that bypasses the problem, rather than fix it.
By the way, if you run the code, make sure you only have the worksheet "1" in the workbook.
Sub Test()
Application.ScreenUpdating = False
Cells.EntireColumn.AutoFit
'Delete foot symbol from distances
Columns("E:E").Replace What:="'", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False
'Sort & Copy Multipule pages
Cells.Sort Key1:=Range("A2"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
Sheets("1").Copy After:=Sheets(1)
Sheets("1 (2)").Copy After:=Sheets(2)
Sheets("1 (3)").Copy After:=Sheets(3)
'Clean each page
Sheets("1 (2)").Select
Dim ws1 As Worksheet
Set ws1 = ActiveSheet
For i = ws1.Range("A65536").End(xlUp).Row To 2 Step -1
If ws1.Cells(i, 1) <> "TRENCH_TYPE" Then
ws1.Rows(i).Delete
End If
Next
Sheets("1 (3)").Select
Dim ws2 As Worksheet
Set ws2 = ActiveSheet
For i = ws2.Range("A65536").End(xlUp).Row To 2 Step -1
If ws2.Cells(i, 1) <> "TRENCH_TYPE_II" Then
ws2.Rows(i).Delete
End If
Next
Sheets("1 (4)").Select
Dim ws3 As Worksheet
Set ws3 = ActiveSheet
For i = ws3.Range("A65536").End(xlUp).Row To 2 Step -1
If ws3.Cells(i, 1) = "TRENCH_TYPE" Then
ws3.Rows(i).Delete
End If
Next
For i = ws3.Range("A65536").End(xlUp).Row To 2 Step -1
If ws3.Cells(i, 1) = "TRENCH_TYPE_II" Then
ws3.Rows(i).Delete
End If
Next
'Trench Type 1
Sheets("1 (2)").Select
Columns("F:G").Delete Shift:=xlToLeft
Columns("C:C").Delete Shift:=xlToLeft
Columns("A:A").Delete Shift:=xlToLeft
'Add Calculation for distance
Dim dLen As Long
dLen = Range("C2").End(xlDown).Row
Range("D2").FormulaR1C1 = "=RC[-3]*RC[-1]"
Range("D2", Cells(dLen, 4)).Formula = Range("D2").Formula
Columns("D:D").Copy
Columns("D:D").PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Columns("A:A").Delete Shift:=xlToLeft
Columns("C:C").Delete Shift:=xlToLeft
Rows("1:1").Delete Shift:=xlUp
'Create Overall Totals
Columns("A:A").AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Columns( _
"C:C"), Unique:=True
Dim cLen As Long
cLen = Range("C1").End(xlDown).Row
Range("D1").FormulaR1C1 = "=SUMIF(C[-3],C[-1],C[-2])"
Range("D1", Cells(cLen, 4)).Formula = Range("D1").Formula
Columns("D:D").Copy
Columns("D:D").PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Columns("A:B").Delete Shift:=xlToLeft
Range("D1").FormulaR1C1 = "I"
Range("D1", Cells(cLen, 4)).Formula = Range("D1").Formula
Range("A1").Select
'Trench Type 2
Sheets("1 (3)").Select
Columns("G:G").Delete Shift:=xlToLeft
Columns("C:C").Delete Shift:=xlToLeft
Columns("A:A").Delete Shift:=xlToLeft
'Erase "Type "
Columns("D:D").Replace What:="TYPE ", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False
'Add Calculation for distance
Columns("D:D").Insert Shift:=xlToRight
Dim dLen2 As Long
dLen2 = Range("C1").End(xlDown).Row
Range("D2").FormulaR1C1 = "=RC[-3]*RC[-1]"
Range("D2", Cells(dLen2, 4)).Formula = Range("D2").Formula
Columns("D:D").Copy
Columns("D:D").PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Columns("A:A").Delete Shift:=xlToLeft
Columns("B:B").Delete Shift:=xlToLeft
Rows("1:1").Delete Shift:=xlUp
'Create Overall Totals
Range("D1").FormulaR1C1 = "=CONCATENATE(RC[-3],RC[-1])"
Range("D1", Cells(dLen2, 4)).Formula = Range("D1").Formula
Columns("D:D").Copy
Columns("A:A").PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Columns("C:D").ClearContents
Columns("A:A").AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Columns( _
"C:C"), Unique:=True
Dim cLen2 As Long
cLen2 = Range("C1").End(xlDown).Row - 1
Range("D1").FormulaR1C1 = "=SUMIF(C[-3],C[-1],C[-2])"
Range("D1", Cells(cLen2, 4)).Formula = Range("D1").Formula
Columns("C:D").Copy
Columns("A:B").PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Columns("C:D").Delete Shift:=xlToLeft
Columns("A:A").Copy
Columns("D:D").PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Columns("A:A").Replace What:="I", Replacement:=""
Columns("D:D").Select
With Selection
.Replace What:="G", Replacement:=""
.Replace What:="P", Replacement:=""
.Replace What:="S", Replacement:=""
.Replace What:="T", Replacement:=""
.Replace What:="C", Replacement:=""
.Replace What:="L", Replacement:=""
.Replace What:="E", Replacement:=""
.Replace What:="A", Replacement:=""
.Replace What:="B", Replacement:=""
.Replace What:="D", Replacement:=""
End With
'Complie 2 & 3 together
If Sheets("1 (2)").Range("a" & Rows.Count).End(xlUp).Row + _
Sheets("1 (3)").Range("a" & Rows.Count).End(xlUp).Row > Rows.Count Then
MsgBox "Too Much Data to fit in One Sheet"
Exit Sub
End If
With Sheets("1 (3)")
.Range("a1", .Range("a" & Rows.Count).End(xlUp)).Resize(, 4).Copy _
Sheets("1 (2)").Range("a" & Rows.Count).End(xlUp).Offset(1)
End With
Sheets("1 (2)").Select
Dim aLen As Long
aLen = Range("A1").End(xlDown).Row
Range("E1").FormulaR1C1 = "=LEN(RC[-4])"
Range("E1", Cells(aLen, 5)).Formula = Range("E1").Formula
Cells.HorizontalAlignment = xlCenter
End Sub
Display More
Re: Compile 2 Lists On 2 Pages Into 1
Thanks guys, works great.
Re: Compile 2 Lists On 2 Pages Into 1
Anyone have any idea if this is even possible? It's gotta be, right?
Re: Compile 2 Lists On 2 Pages Into 1
Well the code above takes 3 colums from one worksheet and makes them one column on the same sheet. What I need should be more clear from the example below.
Sheet 1
A1 B1 C1 D1
A2 B2 C2 D2
A3 B3 C3 D3
Sheet 2
A1 B1 C1 D1
A2 B2 C2 D2
A3 B3 C3 D3
Now those two will be compiled into one
Sheet 3
A1 B1 C1 D1
A2 B2 C2 D2
A3 B3 C3 D3
A1 B1 C1 D1
A2 B2 C2 D2
A3 B3 C3 D3
Does that make sense?
Here's some code that I got from an old thread.
Sub ThreeToOne()
Dim ColALen As Long, ColBLen As Long, ColCLen As Long
ColALen = Range("A65536").End(xlUp).Row
ColBLen = Range("B65536").End(xlUp).Row
ColCLen = Range("C65536").End(xlUp).Row
If ColALen + ColBLen + ColCLen > 65536 Then
MsgBox "Too Much Data to fit in One column"
Exit Sub
End If
Range(Cells(1, 1), Cells(ColALen, 1)).Copy _
Range(Cells(1, 5), Cells(ColALen, 5))
Range(Cells(1, 2), Cells(ColBLen, 2)).Copy _
Range(Cells(ColALen + 1, 5), Cells(ColALen + ColBLen, 5))
Range(Cells(1, 3), Cells(ColCLen, 3)).Copy _
Range(Cells(ColALen + ColBLen + 1, 5), Cells(ColALen + ColBLen + ColCLen, 5))
End Sub
Display More
I'd like to do something similar, yet different. I have 4 columns on 2 pages that I'd like to combine this time around. I'd like to end up with this as my result.
Sheet1ColumnA Sheet1ColumnB Sheet1ColumnC Sheet1ColumnD
Sheet2ColumnA Sheet2ColumnB Sheet2ColumnC Sheet2ColumnD
Thanks in advance.
Re: Delete Row If Condition Not Met
jesus christ i'm dumb. working too hard. thanks.
Here's my code:
Sub DeleteRows()
Dim ws As Worksheet
Set ws = ActiveSheet
For i = ws.Range("A65536").End(xlUp).Row To 2 Step -1
If ws.Cells(i, 9) <> "TRENCH_TYPE" Then
ws.Rows(i).Delete
End If
Next
End Sub
Attached is my worksheet. I want to remove everything but the header row & rows that have "Trench_Type" in column A. However it's deleting everything but my header.
Re: Delete Worksheet If It Exists
Actually, right now I'm trying to figure out how to make it look at the right workbook. If I can't figure it out I'll let you know. Thanks everyone.
Re: Delete Worksheet If It Exists
Hmmm, the code break didn't work unless I did it wrong, but I don't believe I did. Also, I just want to verify that the fact that the code is in my personal workbook wouldn't effect anything, right?
Nevermind, got it (the break) to work. And I just realized that the fact that it's in the personal workbook is exactlly why it's not working. Sorry it took me so long to think about that. Guess I was dropped on my head as a child.
Re: Delete Worksheet If It Exists
no. I don't even know what you mean step code.
Re: Delete Worksheet If It Exists
I'm not sure I'm following what you're saying. Can you put it in terms a caveman can understand cause that's about my intelligence level.
Re: Delete Worksheet If It Exists
There's no problem deleting it manually, no protection or anything. It just seems that code to delete it doesn't work, but I'm not sure why.
Re: Delete Worksheet If It Exists
No, that works the first time you do it. The reason that is bugging is because the next time you run the code, the sheet doesn't get deleted so it can't make a sheet called cleaned because it is already there.
Re: Delete Worksheet If It Exists
I'm using 2000. Also, I just tried pasting it into my file, no luck.
Re: Delete Worksheet If It Exists
That's weird, I tested the attachment & I bugged on me.
As far as clearing the sheet, I might have to do that, but at the same time, there should be a way to do this.