I'm trying to figure out how to past a column of data into a sheet and then rerun the macro again so that I can select a different column to be posted in the sheet that was just created but I cant figure out how to write my IF statements correctly. This is what I have so far. The error tells me that the sheet already exists but I need it to be able to paste into that sheet if it is true and if the sheet doesn't then it needs to create it. I believe there is an error with either the for each loop or the first if statement.
Sub Macro_2424()
Dim FromRange As range
Dim ToRange As range
Set FromRange = Application.InputBox("Enter the range from which you want to copy : ", Type:=8)
FromRange.Select
Selection.Copy
Dim wb As Workbook
Dim ws As Worksheet
Set wb = ActiveWorkbook
For Each ws In wb.Worksheets
If ws.Name = "Data_New" Then
With Worksheets("Data_New")
If IsEmpty(range("A1")) = False Then
Cells(1, Columns.count).End(xlToRight).PasteSpecial Paste:=xlPasteValues
Else
Cells(1, "A").PasteSpecial xlPasteValues, xlPasteSpecialOperationNone
End If
End With
Else
Set wst = Worksheets.Add
wst.Name = "Data_New"
With Worksheets("Data_New")
If IsEmpty(range("A1")) = False Then
Cells(1, Columns.count).End(xlToRight).PasteSpecial Paste:=xlPasteValues
Else
wst.Cells(1, "A").PasteSpecial xlPasteValues, xlPasteSpecialOperationNone
End If
End With
End If
Next
' If wst.Cells(1, "A").Value = "" Then
' wst.Cells(1, "A").PasteSpecial xlPasteValues, xlPasteSpecialOperationNone
' Else
' Cells(1, Columns.count).End(xlToRight).PasteSpecial Paste:=xlPasteValues
' End If
'wst.Cells(1, "A").PasteSpecial xlPasteValues, xlPasteSpecialOperationNone
Cells.Columns.AutoFit
End Sub