Posts by Brian Walters
-
-
Re: Copy Row To One Of Two Worksheets Based On Match Condition
Here is a clunky way to do it using a macro.
Code
Display MoreSub Compare() Dim i As Long Sheets("need_to_delete").Select Columns("A:A").Copy Sheets("Sheet2").Select Range("A1").PasteSpecial xlPasteAll Sheets("Sheet3").Select Range("A1").PasteSpecial xlPasteAll Sheets("Sheet1").Select Columns("A:A").Copy Sheets("Sheet2").Select Range("C1").PasteSpecial xlPasteAll Sheets("Sheet3").Select Range("C1").PasteSpecial xlPasteAll 'NonMatches Sheets("Sheet2").Select Range("B1").FormulaR1C1 = "=IF(ISERROR(VLOOKUP(RC[-1],C[1],1,FALSE)),0,1)" Range("B1").Select Selection.AutoFill Destination:=Range("B1:B" & Range("A65536").End(xlUp).Row) Range("D1").FormulaR1C1 = "=IF(ISERROR(VLOOKUP(RC[-1],C[-3],1,FALSE)),0,1)" Range("D1").Select Selection.AutoFill Destination:=Range("D1:D" & Range("C65536").End(xlUp).Row) Cells.Copy Range("A1").PasteSpecial xlPasteValues For i = Range("A65536").End(xlUp).Row To 1 Step -1 If Range("B" & i).Value = 1 Then Range("A" & i & ":B" & i).Delete xlUp Next i For i = Range("C65536").End(xlUp).Row To 1 Step -1 If Range("D" & i).Value = 1 Then Range("C" & i & ":D" & i).Delete xlUp Next i Range("C1:C" & Range("C65536").End(xlUp).Row).Copy Range("A" & Range("A65536").End(xlUp).Row + 1).PasteSpecial xlPasteAll Columns("B:D").Delete 'Matches Sheets("Sheet3").Select Range("B1").FormulaR1C1 = "=IF(ISERROR(VLOOKUP(RC[-1],C[1],1,FALSE)),0,1)" Range("B1").Select Selection.AutoFill Destination:=Range("B1:B" & Range("A65536").End(xlUp).Row) Columns("B:B").Copy Range("B1").PasteSpecial xlPasteValues For i = Range("A65536").End(xlUp).Row To 1 Step -1 If Range("B" & i).Value = 0 Then Range("B" & i).EntireRow.Delete xlUp Next i Columns("B:C").Delete End Sub
HTH
Sorry, I forgot you had 4 columns of data.
Code
Display MoreSub Compare() Dim i As Long Sheets("need_to_delete").Select Columns("A:D").Copy Sheets("Sheet2").Select Range("A1").PasteSpecial xlPasteAll Sheets("Sheet3").Select Range("A1").PasteSpecial xlPasteAll Sheets("Sheet1").Select Columns("A:D").Copy Sheets("Sheet2").Select Range("F1").PasteSpecial xlPasteAll Sheets("Sheet3").Select Range("F1").PasteSpecial xlPasteAll 'NonMatches Sheets("Sheet2").Select Range("E1").FormulaR1C1 = "=IF(ISERROR(VLOOKUP(RC[-4],C[1],1,FALSE)),0,1)" Range("E1").Select Selection.AutoFill Destination:=Range("E1:E" & Range("A65536").End(xlUp).Row) Range("J1").FormulaR1C1 = "=IF(ISERROR(VLOOKUP(RC[-4],C[-9],1,FALSE)),0,1)" Range("J1").Select Selection.AutoFill Destination:=Range("J1:J" & Range("G65536").End(xlUp).Row) Cells.Copy Range("A1").PasteSpecial xlPasteValues For i = Range("A65536").End(xlUp).Row To 1 Step -1 If Range("E" & i).Value = 1 Then Range("A" & i & ":E" & i).Delete xlUp Next i For i = Range("F65536").End(xlUp).Row To 1 Step -1 If Range("J" & i).Value = 1 Then Range("F" & i & ":J" & i).Delete xlUp Next i Range("F1:I" & Range("F65536").End(xlUp).Row).Copy Range("A" & Range("A65536").End(xlUp).Row + 1).PasteSpecial xlPasteAll Columns("E:J").Delete 'Matches Sheets("Sheet3").Select Range("E1").FormulaR1C1 = "=IF(ISERROR(VLOOKUP(RC[-4],C[1],1,FALSE)),0,1)" Range("E1").Select Selection.AutoFill Destination:=Range("E1:E" & Range("A65536").End(xlUp).Row) Columns("E:E").Copy Range("E1").PasteSpecial xlPasteValues For i = Range("A65536").End(xlUp).Row To 1 Step -1 If Range("E" & i).Value = 0 Then Range("E" & i).EntireRow.Delete xlUp Next i Columns("E:I").Delete End Sub
-
-
-
-
-
Re: Macro To Delete Entire Row Based On Specific Word In Cell With Multiple Words
Based on a post by Bill Rockenbach, I think this will work
Code
Display MoreSub DoIt() Dim Sentences Dim i As Long Dim iWordPos As Integer Sentences = Range("A1", Range("A65536").End(xlUp)) lRow = 0 For i = Range("A65536").End(xlUp).Row To 1 Step -1 iWordPos = InStr(LCase(Sentences(i, 1)), LCase("hospital")) If iWordPos > 0 Then Range("A" & i).EntireRow.Delete shift:=xlShiftUp End If Next i End Sub
I think you can use this to modify the macro in your other post where you want to highlight certain cells.
HTH -
Re: Macro To Highlight Cell With Specific Word And Then Repeat Itself For Entire Column
Try this
Code
Display MoreSub find_highlight() Dim W As String, rng As Range W = InputBox("What to find?") For Each rng In ActiveSheet.UsedRange If rng.Value = W Then rng.Select With Selection.Interior .ColorIndex = 6 .Pattern = xlSolid .PatternColorIndex = xlAutomatic End With End If Next rng End Sub
HTH -
-
Re: Lookup And If Statements
Attached is my file that works.
-
Re: Calculate Plates Per Side For A Weightbar With Specific Weight Choices
The attached file is a parred down version of a spreadsheet I created to help another member calculate how many boards of differing lengths could be gotten out of a long piece of wood. I split your weights in half since the sides will be uniform. HTH
-
Re: Date Formats In Visual Basic
I downloaded the WinRAR software and extracted the file. This worked for me
CodeWith Obj1.ActiveWorkbook.ActiveSheet .Range(.Cells(2, 15), .Cells(2, 5).End(-4121).End(-4161).Offset(0, 2)).FormulaR1C1 = "=RC[-10]+RC[-9]" .Range(.Cells(2, 15), .Cells(2, 5).End(-4121).End(-4161).Offset(0, 2)).NumberFormat = "m/d/yyyy h:mm" '*** This line was added *** .Range(.Cells(2, 16), .Cells(2, 15).End(-4121).Offset(0, 1)).FormulaR1C1 = "=RC[-7]" a = .Range(.Cells(2, 15), .Cells(2, 16).End(-4121)) End With
-
-
Re: Lookup And If Statements
Odd...I copy the formula into F2 and then copy F2 down and it works.
-
-
Re: Transformin And Pasting
Try this macro
Code
Display MoreSub PasteThem() Dim rng As Range, i As Long Sheets("Paste_from").Select Set rng = Sheets("Paste_from").Range("C3") Do Until rng.Row = Sheets("Paste_from").Range("C65536").End(xlUp).Row + 1 If Len(rng.Value) > 0 Then Sheets("Paste_In").Select For i = 1 To Range("A1").End(xlToRight).Column If Cells(1, i).Value = "Apt " & rng.Value Then Cells(3, i).Value = Cells(3, i).Value + rng.Offset(0, 6).Value Next i End If Set rng = rng.Offset(1, 0) Loop End Sub
[hr]*[/hr] Auto Merged Post;[dl]*[/dl]I have added a button to run the macro as well as the ability to loop through all the sheets in the workbook and paste the results into their own line on the "Paste_In" sheet. As far as starting at a different place on each "Paste_From" sheet, the macro will start 1 row down from the last row that has something in Column A. So if you want to start at row 12 on a particular sheet, then just type something in cell A11 and make sure that all cells in column A below row 11 are blank.
More Updates -
Re: Lookup And If Statements
You can use this formula =IF(LEN(B2)=0,"",IF(AND(VLOOKUP(A2,$A3:$D$99,4,FALSE)=D2,VLOOKUP(A2,$A3:$C$99,3,FALSE)>0,B2>A2),"Possible","")).
HTH
-
Re: Jumping Lines (iso Of Smooth Ones) In A Chart
Andy Pope is the master of charts\graphs in Excel. Look at this site to see if it has what you are looking for http://www.andypope.info/charts/stepchart.htm
HTH
-
Re: Copy PDF Files Matching List Into Different Folder
I got this to work for me
Code
Display MoreSub MovePDFs() Dim fs, objFolder, rw As Long, MyFile As String Set fs = CreateObject("Scripting.FileSystemObject") For rw = 1 To 3 'Change these to your loop parameters If Dir("C:\Active\" & Range("B" & rw).Value, vbDirectory) = "" Then Set objFolder = fs.CreateFolder("C:\Active\" & Range("B" & rw).Value) MyFile = Dir("C:\Storage\", vbDirectory) Do Until MyFile = "" If Not (MyFile = "." Or MyFile = "..") Then ' Ignore the current directory and the encompassing directory. If Left(MyFile, 8) = CStr(Range("A" & rw).Value) And Right(MyFile, 4) = ".pdf" Then FileCopy "C:\Storage\" & MyFile, "C:\Active\" & Range("B" & rw).Value & "\" & MyFile End If End If MyFile = Dir Loop Next rw End Sub
-
Re: Hide Rows Across All Sheets Where Row Sums To Zero
How about capturing the starting sheet's name at the beginning of the code and then using that at the end to return to the starting sheet? Something like
Code
Display MoreSub HideRows() Application.ScreenUpdating = False Dim WS As Worksheet, StartSht as Worksheet Set StartSht = ActiveSheet For Each WS In ThisWorkbook.Worksheets WS.Select ActiveSheet.Unprotect Password:="admin" On Error Resume Next With Range("e4:e34") .EntireRow.Hidden = False For i = 1 To .Rows.Count If WorksheetFunction.Sum(.Rows(i)) = 0 Then .Rows(i).EntireRow.Hidden = True End If Next i ActiveSheet.Protect Password:="admin" End With Next WS StartSht.Select Application.ScreenUpdating = True End Sub