largeselection
Active Member
- Joined
- Aug 4, 2008
- Messages
- 358
I have a workbook where I can click a cell on the first sheet and make a checkmark. Based on that checkmark it will go to a data sheet, copy the corresponding column, then paste it into a report sheet.
The problem that I'm having is that everytime I check off a cell, it runs the code from the beginning and recopies the stuff it already copied.
So if I click Name, Height, and Weight on the first sheet (A1,B1,C1).
It runs the macro for the first click on A1 and copies Name to the report sheet. Then runs it for the second click on B1 and because A1 is still checked , copies Name and Height to the report sheet, and then for the third click on C1 it does the same thing so my report sheet has Name, Name, Name, Height, Height, Weight on it.
How can I get it to not copy/paste the same column again. The code I'm working with follows:
Private Sub Worksheet_SelectionChange(ByVal target As Range)
If target.Column = 2 Then Exit Sub
If target.Row < 2 Then Exit Sub
If target.Row > 14 Then Exit Sub
If target.Count > 1 Then Exit Sub
If IsEmpty(target) Then
target.Formula = "=CHAR(252)"
target.Value = target.Value
With target.Font
.Name = "Wingdings"
.FontStyle = "Bold"
.Size = 8
End With
target.Borders.LineStyle = xlContinuous
Call TestClick
Else
target.ClearContents
End If
End Sub
Private Sub TestClick()
If Not IsEmpty(Range("a1")) Then
Builder "Name"
End If
If Not IsEmpty(Range("b1")) Then
Builder "Height"
End If
If Not IsEmpty(Range("c1")) Then
Builder "Weight"
End If
Sub Builder(MyHeader As String)
Dim MyColumn As Integer
With Worksheets("DATA")
MyColumn = .Rows(1).Find(What:=MyHeader, After:=.Cells(1, 1), LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Column
.Columns(MyColumn).Copy Worksheets("REPORT").Range("A1").End(xlToRight).Offset(0, 1)
End With
End Sub
Just in general, how can I alter this? And how can I put in code to skip portions of if/then criteria if they have already been completed. I thought about just putting in code to delete duplicate columns, but I have 300+ columns to check from so the report sheet rapidly fills up...
The problem that I'm having is that everytime I check off a cell, it runs the code from the beginning and recopies the stuff it already copied.
So if I click Name, Height, and Weight on the first sheet (A1,B1,C1).
It runs the macro for the first click on A1 and copies Name to the report sheet. Then runs it for the second click on B1 and because A1 is still checked , copies Name and Height to the report sheet, and then for the third click on C1 it does the same thing so my report sheet has Name, Name, Name, Height, Height, Weight on it.
How can I get it to not copy/paste the same column again. The code I'm working with follows:
Private Sub Worksheet_SelectionChange(ByVal target As Range)
If target.Column = 2 Then Exit Sub
If target.Row < 2 Then Exit Sub
If target.Row > 14 Then Exit Sub
If target.Count > 1 Then Exit Sub
If IsEmpty(target) Then
target.Formula = "=CHAR(252)"
target.Value = target.Value
With target.Font
.Name = "Wingdings"
.FontStyle = "Bold"
.Size = 8
End With
target.Borders.LineStyle = xlContinuous
Call TestClick
Else
target.ClearContents
End If
End Sub
Private Sub TestClick()
If Not IsEmpty(Range("a1")) Then
Builder "Name"
End If
If Not IsEmpty(Range("b1")) Then
Builder "Height"
End If
If Not IsEmpty(Range("c1")) Then
Builder "Weight"
End If
Sub Builder(MyHeader As String)
Dim MyColumn As Integer
With Worksheets("DATA")
MyColumn = .Rows(1).Find(What:=MyHeader, After:=.Cells(1, 1), LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Column
.Columns(MyColumn).Copy Worksheets("REPORT").Range("A1").End(xlToRight).Offset(0, 1)
End With
End Sub
Just in general, how can I alter this? And how can I put in code to skip portions of if/then criteria if they have already been completed. I thought about just putting in code to delete duplicate columns, but I have 300+ columns to check from so the report sheet rapidly fills up...