Fat code

Wes

Board Regular
Joined
Jan 30, 2004
Messages
195
I'm looking to copy data from one sheet to another. The data to copy on sheet1 is in different areas and in colums but needs to go to rows. So two questions:

1). The sheet to recieve the data needs the data copied to rows. Can a range be turned horizontally from vertiacal (colum to row)?

so Sheet1.range ("b1"b4") data
to
Sheet2.range(a1:a4)

2). Any suggestions on how to place the next copied data to the next row down if the previous was already full?


Here is the code I've started with.

Appreciate any tips. :confused:

Private Sub CommandButton1_Click()

Sheets("Daily Input").Range("b1").Copy Sheets("Database").Range("A2")
Sheets("Daily Input").Range("b2").Copy Sheets("Database").Range("b2")
Sheets("Daily Input").Range("b3").Copy Sheets("Database").Range("c2")
Sheets("Daily Input").Range("b4").Copy Sheets("Database").Range("d2")

Sheets("Daily Input").Range("c7").Copy Sheets("Database").Range("e2")
Sheets("Daily Input").Range("c8").Copy Sheets("Database").Range("f2")
Sheets("Daily Input").Range("c9").Copy Sheets("Database").Range("g2")


Sheets("Daily Input").Range("b1").Value = Sheets("Database").Range("A2") + 1
Sheets("Daily Input").Range("b2").Value = ""
Sheets("Daily Input").Range("b3").Value = ""
Sheets("Daily Input").Range("b4").Value = ""

Sheets("Daily Input").Range("c7").Value = ""
Sheets("Daily Input").Range("c8").Value = ""
Sheets("Daily Input").Range("c9").Value = ""

End Sub
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Use the XL/VBA native capabilities rather than VBA brute force.

Code:
    Sheets("Daily Input").Range("b1").Resize(4, 1).Copy
    Sheets("Database").Range("A2").PasteSpecial _
        Paste:=xlPasteAll, Operation:=xlNone, _
        SkipBlanks:=False, Transpose:=True
    'Do the same for c7:c9
    
    With Sheets("Daily Input").Range("b1")
    .Value = .Value + 1
    .Offset(1, 0).Resize(3, 1).ClearContents
        End With
    'do the same with c7:c9

To find the first empty cell of interest, see http://www.mrexcel.com/board2/viewtopic.php?t=46684&highlight=findfirstempty

Wes said:
I'm looking to copy data from one sheet to another. {snip}
Private Sub CommandButton1_Click()

Sheets("Daily Input").Range("b1").Copy Sheets("Database").Range("A2")
Sheets("Daily Input").Range("b2").Copy Sheets("Database").Range("b2")
Sheets("Daily Input").Range("b3").Copy Sheets("Database").Range("c2")
Sheets("Daily Input").Range("b4").Copy Sheets("Database").Range("d2")

Sheets("Daily Input").Range("c7").Copy Sheets("Database").Range("e2")
Sheets("Daily Input").Range("c8").Copy Sheets("Database").Range("f2")
Sheets("Daily Input").Range("c9").Copy Sheets("Database").Range("g2")


Sheets("Daily Input").Range("b1").Value = Sheets("Database").Range("A2") + 1
Sheets("Daily Input").Range("b2").Value = ""
Sheets("Daily Input").Range("b3").Value = ""
Sheets("Daily Input").Range("b4").Value = ""

Sheets("Daily Input").Range("c7").Value = ""
Sheets("Daily Input").Range("c8").Value = ""
Sheets("Daily Input").Range("c9").Value = ""

End Sub
 
Upvote 0
tusharm

Works great but it over writes the data of the Database sheet. Is there an xlDown or xlUp function that should go it somewhere to prevent the over write?

Wes
 
Upvote 0
Yes. That was the reference to the other discussion about using FindFirstEmpty.
 
Upvote 0
tusharm

Well between the two I've struck Oil here. By combining bits and pieces I have what I need. And for my limited programming abilities I can follow through and correct as necessary.

Thanks, (y)


Wes


Private Sub CommandButton1_Click()
'Identify the range to see if it is full_
'and if it is then go down 1 space in the same column
'and continue until it finds an empty space

Range("d12").Select
Do
If IsEmpty(ActiveCell) = False Then
ActiveCell.Offset(1, 0).Select
End If
Loop Until IsEmpty(ActiveCell) = True

' Now this takes the information from the individual cells
'and then places them in the destination cells

ActiveCell.Value = Range("b1")
ActiveCell.Offset(0, 1) = Range("b2")
ActiveCell.Offset(0, 2) = Range("b3")
ActiveCell.Offset(0, 3) = Range("b4")
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,839
Messages
6,121,891
Members
449,058
Latest member
Guy Boot

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top