snuffnchess
Board Regular
- Joined
- May 15, 2015
- Messages
- 71
- Office Version
- 365
- Platform
- Windows
While I was able to get code to work and do what it is I am wanting, something tells me that there are much better ways to do what I am trying to accomplish?
Essentially, I am wanting to copy the contents of cells from "ClientDB" BJ4:BK(lastrow), BN4:BO(lastrow) - and so on
and then have those contents paste only into column A and B of the Birthdays tab. Essentially I want to be able to enter in the month (for example May) and have an auto Filter of everybody whose birthday is that month.
To Copy the persons Name and DOB I am using:
And then to eliminate the blank rows I am using
Essentially, I am wanting to copy the contents of cells from "ClientDB" BJ4:BK(lastrow), BN4:BO(lastrow) - and so on
and then have those contents paste only into column A and B of the Birthdays tab. Essentially I want to be able to enter in the month (for example May) and have an auto Filter of everybody whose birthday is that month.
To Copy the persons Name and DOB I am using:
Code:
[/COLOR]Sub Macro1()
Dim bd As Worksheet
Set bd = Worksheets("Birthdays")
Dim CDB As Worksheet
Set CDB = Worksheets("ClientDB")
Dim lastrow As Long
Dim lastbdrow As Long
With Sheets("Birthdays")
If Application.WorksheetFunction.CountA(.Cells) <> 0 Then
lastbdrow = .Cells.Find(What:="*", _
After:=.Range("A1"), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
Else
lastbdrow = 1
End If
End With
With Sheets("ClientDB")
If Application.WorksheetFunction.CountA(.Cells) <> 0 Then
lastrow = .Cells.Find(What:="*", _
After:=.Range("A1"), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
Else
lastrow = 1
End If
End With
Dim bdRow As Long
bdRow = Application.WorksheetFunction.CountA(bd.Range("A:A")) + 1
Sheets("Birthdays").Select
Range("A2:B" & lastrow).ClearContents
Sheets("ClientDB").Select
Range("BI4:BJ" & lastrow).Select
Selection.Copy
Sheets("Birthdays").Select
Range("A2").Select
bd.Cells(bdRow, 1).Select
ActiveSheet.Paste
' Sheets("ClientDB").Select
' Range("BN4:BO4").Select
' Range(Selection, Selection.End(xlDown)).Select
' Selection.Copy
' bdRow = Application.WorksheetFunction.CountA(bd.Range("A:A")) + 1
' Sheets("Birthdays").Select
' bd.Cells(bdRow, 1).Select
' ActiveSheet.Paste
End Sub[COLOR=#333333]
And then to eliminate the blank rows I am using
Code:
[/COLOR]Sub Select_Blank_Rows()
Dim rRow As Range
Dim rSelect As Range
Dim rSelection As Range
Dim lastrow As Long
With Sheets("Birthdays")
If Application.WorksheetFunction.CountA(.Cells) <> 0 Then
lastrow = .Cells.Find(What:="*", _
After:=.Range("A1"), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
Else
lastrow = 1
End If
End With
'MsgBox lastrow
If Selection.Cells.Count = 1 Then
Set rSelection = Range("A1:B" & lastrow)
Else
Set rSelection = Range("A1:B" & lastrow)
End If
For Each rRow In rSelection.Rows
If WorksheetFunction.CountA(rRow) = 0 Then
If rSelect Is Nothing Then
Set rSelect = rRow
Else
Set rSelect = Union(rSelect, rRow)
End If
End If
Next rRow
rSelect.Rows.Delete Shift:=xlShiftUp
End Sub[COLOR=#333333]