#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 493
Default Code

Dear ALL

I have the following question:

I placed the button on the excel sheet and assign a macro which cuts the
cells' values from range b1:b4 and pastes them into range a10:d10 everything
is ok and works perfectly, but how can I do so that when I press the button
again the new values which i type in range b1:b4 placed in a11:d11 ? and so
on, is it possible?

Please help me with this
Thank you in advance

My Code:
Private Sub CommandButton1_Click()
If Range("A10") = "" Then

Range("B1").Select
Selection.Cut
Range("A10").Select
ActiveSheet.Paste
Range("B2").Select
Selection.Cut
Range("B10").Select
ActiveSheet.Paste
Range("B3").Select
Selection.Cut
Range("C10").Select
ActiveSheet.Paste
Range("B4").Select
Selection.Cut
Range("D10").Select
ActiveSheet.Paste
Else
Range("B1").Select
Selection.Cut
Range("A11").Select
ActiveSheet.Paste
Range("B2").Select
Selection.Cut
Range("B11").Select
ActiveSheet.Paste
Range("B3").Select
Selection.Cut
Range("C11").Select
ActiveSheet.Paste
Range("B4").Select
Selection.Cut
Range("D11").Select
ActiveSheet.Paste

End If

End Sub

what should I do to continue the code for next ranges?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 226
Default Code

Try

Private Sub CommandButton1_Click()

Dim rowNum As Long

If Range("A10").Value < Empty Then
rowNum = Cells(Rows.Count, 1).End(xlUp).Row + 1
Else
rowNum = 10
End If

Range("B1").Cut Destination:=Cells(rowNum, 1)
Range("B2").Cut Destination:=Cells(rowNum, 2)
Range("B3").Cut Destination:=Cells(rowNum, 3)
Range("B4").Cut Destination:=Cells(rowNum, 4)

End Sub

Hope this helps
Rowan

"Alex" wrote:

Dear ALL

I have the following question:

I placed the button on the excel sheet and assign a macro which cuts the
cells' values from range b1:b4 and pastes them into range a10:d10 everything
is ok and works perfectly, but how can I do so that when I press the button
again the new values which i type in range b1:b4 placed in a11:d11 ? and so
on, is it possible?

Please help me with this
Thank you in advance

My Code:
Private Sub CommandButton1_Click()
If Range("A10") = "" Then

Range("B1").Select
Selection.Cut
Range("A10").Select
ActiveSheet.Paste
Range("B2").Select
Selection.Cut
Range("B10").Select
ActiveSheet.Paste
Range("B3").Select
Selection.Cut
Range("C10").Select
ActiveSheet.Paste
Range("B4").Select
Selection.Cut
Range("D10").Select
ActiveSheet.Paste
Else
Range("B1").Select
Selection.Cut
Range("A11").Select
ActiveSheet.Paste
Range("B2").Select
Selection.Cut
Range("B11").Select
ActiveSheet.Paste
Range("B3").Select
Selection.Cut
Range("C11").Select
ActiveSheet.Paste
Range("B4").Select
Selection.Cut
Range("D11").Select
ActiveSheet.Paste

End If

End Sub

what should I do to continue the code for next ranges?

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 493
Default Code


WOW Thank you Rowan
It Works Perfectly It's hard for me to understand some parts of code but
Thank you again
"Rowan" wrote:

Try

Private Sub CommandButton1_Click()

Dim rowNum As Long

If Range("A10").Value < Empty Then
rowNum = Cells(Rows.Count, 1).End(xlUp).Row + 1
Else
rowNum = 10
End If

Range("B1").Cut Destination:=Cells(rowNum, 1)
Range("B2").Cut Destination:=Cells(rowNum, 2)
Range("B3").Cut Destination:=Cells(rowNum, 3)
Range("B4").Cut Destination:=Cells(rowNum, 4)

End Sub

Hope this helps
Rowan

"Alex" wrote:

Dear ALL

I have the following question:

I placed the button on the excel sheet and assign a macro which cuts the
cells' values from range b1:b4 and pastes them into range a10:d10 everything
is ok and works perfectly, but how can I do so that when I press the button
again the new values which i type in range b1:b4 placed in a11:d11 ? and so
on, is it possible?

Please help me with this
Thank you in advance

My Code:
Private Sub CommandButton1_Click()
If Range("A10") = "" Then

Range("B1").Select
Selection.Cut
Range("A10").Select
ActiveSheet.Paste
Range("B2").Select
Selection.Cut
Range("B10").Select
ActiveSheet.Paste
Range("B3").Select
Selection.Cut
Range("C10").Select
ActiveSheet.Paste
Range("B4").Select
Selection.Cut
Range("D10").Select
ActiveSheet.Paste
Else
Range("B1").Select
Selection.Cut
Range("A11").Select
ActiveSheet.Paste
Range("B2").Select
Selection.Cut
Range("B11").Select
ActiveSheet.Paste
Range("B3").Select
Selection.Cut
Range("C11").Select
ActiveSheet.Paste
Range("B4").Select
Selection.Cut
Range("D11").Select
ActiveSheet.Paste

End If

End Sub

what should I do to continue the code for next ranges?

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 226
Default Code

You're welcome. Quick (and incomplete) explanation.

You don't need to select cells to carry out operations on them. So your code:

Range("B1").Select
Selection.Cut
Range("A10").Select
ActiveSheet.Paste


can be rewritten as:

Range("B1").Cut Destination:= Range("A10")


You can refer to a range (cell) using the Cells property so which consists
of a row reference followed by a column reference i.e. Cells(row,column). So

Range("A10") becomes Cells(10,1) giving you:

Range("B1").Cut Destination:= Cells(10,1)


Rather than actually stating the row number I have used a variable called
rowNum. If Cell A10 is not empty then rowNum is set by starting at the last
row in column A in your version of Excel (rows.count,1) and then moving up to
the first populated cell (End(xlUp).Row) and adding 1.
If A10 is empty then rowNum is set to the value 10.

I hope this has made some sense and not left you even more confused :)

Rowan


"Alex" wrote:


WOW Thank you Rowan
It Works Perfectly It's hard for me to understand some parts of code but
Thank you again
"Rowan" wrote:

Try

Private Sub CommandButton1_Click()

Dim rowNum As Long

If Range("A10").Value < Empty Then
rowNum = Cells(Rows.Count, 1).End(xlUp).Row + 1
Else
rowNum = 10
End If

Range("B1").Cut Destination:=Cells(rowNum, 1)
Range("B2").Cut Destination:=Cells(rowNum, 2)
Range("B3").Cut Destination:=Cells(rowNum, 3)
Range("B4").Cut Destination:=Cells(rowNum, 4)

End Sub

Hope this helps
Rowan

"Alex" wrote:

Dear ALL

I have the following question:

I placed the button on the excel sheet and assign a macro which cuts the
cells' values from range b1:b4 and pastes them into range a10:d10 everything
is ok and works perfectly, but how can I do so that when I press the button
again the new values which i type in range b1:b4 placed in a11:d11 ? and so
on, is it possible?

Please help me with this
Thank you in advance

My Code:
Private Sub CommandButton1_Click()
If Range("A10") = "" Then

Range("B1").Select
Selection.Cut
Range("A10").Select
ActiveSheet.Paste
Range("B2").Select
Selection.Cut
Range("B10").Select
ActiveSheet.Paste
Range("B3").Select
Selection.Cut
Range("C10").Select
ActiveSheet.Paste
Range("B4").Select
Selection.Cut
Range("D10").Select
ActiveSheet.Paste
Else
Range("B1").Select
Selection.Cut
Range("A11").Select
ActiveSheet.Paste
Range("B2").Select
Selection.Cut
Range("B11").Select
ActiveSheet.Paste
Range("B3").Select
Selection.Cut
Range("C11").Select
ActiveSheet.Paste
Range("B4").Select
Selection.Cut
Range("D11").Select
ActiveSheet.Paste

End If

End Sub

what should I do to continue the code for next ranges?

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Code

Hi Alex,

Try:

Private Sub CommandButton1_Click()
Dim rng As Range

If Application.CountA(Me.Range("A10:D10")) = 0 Then
Set rng = Me.Range("A10")
Else
Set rng = Cells(Rows.Count, "A").End(xlUp)(2)
End If

Me.Range("B1:B4").Copy
rng.PasteSpecial Paste:=xlAll, _
Operation:=xlNone, _
SkipBlanks:=False, _
Transpose:=True

End Sub


---
Regards,
Norman



"Alex" wrote in message
...
Dear ALL

I have the following question:

I placed the button on the excel sheet and assign a macro which cuts the
cells' values from range b1:b4 and pastes them into range a10:d10
everything
is ok and works perfectly, but how can I do so that when I press the
button
again the new values which i type in range b1:b4 placed in a11:d11 ? and
so
on, is it possible?

Please help me with this
Thank you in advance

My Code:
Private Sub CommandButton1_Click()
If Range("A10") = "" Then

Range("B1").Select
Selection.Cut
Range("A10").Select
ActiveSheet.Paste
Range("B2").Select
Selection.Cut
Range("B10").Select
ActiveSheet.Paste
Range("B3").Select
Selection.Cut
Range("C10").Select
ActiveSheet.Paste
Range("B4").Select
Selection.Cut
Range("D10").Select
ActiveSheet.Paste
Else
Range("B1").Select
Selection.Cut
Range("A11").Select
ActiveSheet.Paste
Range("B2").Select
Selection.Cut
Range("B11").Select
ActiveSheet.Paste
Range("B3").Select
Selection.Cut
Range("C11").Select
ActiveSheet.Paste
Range("B4").Select
Selection.Cut
Range("D11").Select
ActiveSheet.Paste

End If

End Sub

what should I do to continue the code for next ranges?





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 493
Default Code

Rowan your explanation was really usefull want to thank you for that.

Here I also want to extend my appreciation to Norman Jones, his version is
also good because:

In Rowan version if I have some datas in the lower fields the cutted cells
will go under the datas, as to Norman's one My Range is going down wheter I
have anything or not :)

Once Again Thank you all

I Love this Community and Love you all.

"Norman Jones" wrote:

Hi Alex,

Try:

Private Sub CommandButton1_Click()
Dim rng As Range

If Application.CountA(Me.Range("A10:D10")) = 0 Then
Set rng = Me.Range("A10")
Else
Set rng = Cells(Rows.Count, "A").End(xlUp)(2)
End If

Me.Range("B1:B4").Copy
rng.PasteSpecial Paste:=xlAll, _
Operation:=xlNone, _
SkipBlanks:=False, _
Transpose:=True

End Sub


---
Regards,
Norman



"Alex" wrote in message
...
Dear ALL

I have the following question:

I placed the button on the excel sheet and assign a macro which cuts the
cells' values from range b1:b4 and pastes them into range a10:d10
everything
is ok and works perfectly, but how can I do so that when I press the
button
again the new values which i type in range b1:b4 placed in a11:d11 ? and
so
on, is it possible?

Please help me with this
Thank you in advance

My Code:
Private Sub CommandButton1_Click()
If Range("A10") = "" Then

Range("B1").Select
Selection.Cut
Range("A10").Select
ActiveSheet.Paste
Range("B2").Select
Selection.Cut
Range("B10").Select
ActiveSheet.Paste
Range("B3").Select
Selection.Cut
Range("C10").Select
ActiveSheet.Paste
Range("B4").Select
Selection.Cut
Range("D10").Select
ActiveSheet.Paste
Else
Range("B1").Select
Selection.Cut
Range("A11").Select
ActiveSheet.Paste
Range("B2").Select
Selection.Cut
Range("B11").Select
ActiveSheet.Paste
Range("B3").Select
Selection.Cut
Range("C11").Select
ActiveSheet.Paste
Range("B4").Select
Selection.Cut
Range("D11").Select
ActiveSheet.Paste

End If

End Sub

what should I do to continue the code for next ranges?




  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Code

Hi Alex,

Here I also want to extend my appreciation to Norman Jones, his version is
also good because:


Thank you.

However, given a choice, I would go with Greg's more elegant code.

---
Regards,
Norman



"Alex" wrote in message
...
Rowan your explanation was really usefull want to thank you for that.

Here I also want to extend my appreciation to Norman Jones, his version is
also good because:

In Rowan version if I have some datas in the lower fields the cutted cells
will go under the datas, as to Norman's one My Range is going down wheter
I
have anything or not :)

Once Again Thank you all

I Love this Community and Love you all.

"Norman Jones" wrote:

Hi Alex,

Try:

Private Sub CommandButton1_Click()
Dim rng As Range

If Application.CountA(Me.Range("A10:D10")) = 0 Then
Set rng = Me.Range("A10")
Else
Set rng = Cells(Rows.Count, "A").End(xlUp)(2)
End If

Me.Range("B1:B4").Copy
rng.PasteSpecial Paste:=xlAll, _
Operation:=xlNone, _
SkipBlanks:=False, _
Transpose:=True

End Sub


---
Regards,
Norman



"Alex" wrote in message
...
Dear ALL

I have the following question:

I placed the button on the excel sheet and assign a macro which cuts
the
cells' values from range b1:b4 and pastes them into range a10:d10
everything
is ok and works perfectly, but how can I do so that when I press the
button
again the new values which i type in range b1:b4 placed in a11:d11 ?
and
so
on, is it possible?

Please help me with this
Thank you in advance

My Code:
Private Sub CommandButton1_Click()
If Range("A10") = "" Then

Range("B1").Select
Selection.Cut
Range("A10").Select
ActiveSheet.Paste
Range("B2").Select
Selection.Cut
Range("B10").Select
ActiveSheet.Paste
Range("B3").Select
Selection.Cut
Range("C10").Select
ActiveSheet.Paste
Range("B4").Select
Selection.Cut
Range("D10").Select
ActiveSheet.Paste
Else
Range("B1").Select
Selection.Cut
Range("A11").Select
ActiveSheet.Paste
Range("B2").Select
Selection.Cut
Range("B11").Select
ActiveSheet.Paste
Range("B3").Select
Selection.Cut
Range("C11").Select
ActiveSheet.Paste
Range("B4").Select
Selection.Cut
Range("D11").Select
ActiveSheet.Paste

End If

End Sub

what should I do to continue the code for next ranges?






  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 747
Default Code

Try:

Private Sub CommandButton1_Click()
Dim rng1 As Range, rng2 As Range
Dim rw As Long
rw = Cells(Rows.Count, 1).End(xlUp).Row + 1
rw = Application.Max(rw, 10)
Set rng1 = Range("B1:B4")
Set rng2 = Range(Cells(rw, 1), Cells(rw, 4))
rng2.Value = Application.Transpose(rng1.Value)
rng1.ClearContents
End Sub

Regards,
Greg
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
split post code (zip code) out of cell that includes full address Concord Excel Discussion (Misc queries) 4 October 15th 09 06:59 PM
Drop Down/List w/Code and Definition, only code entered when selec Spiritdancer Excel Worksheet Functions 2 November 2nd 07 03:57 AM
Create a newworksheet with VBA code and put VBA code in the new worksheet module ceshelman Excel Programming 4 June 15th 05 04:37 PM
stubborn Excel crash when editing code with code, one solution Brian Murphy Excel Programming 0 February 20th 05 05:56 AM
VBA code delete code but ask for password and unlock VBA protection WashoeJeff Excel Programming 0 January 27th 04 07:07 AM


All times are GMT +1. The time now is 09:42 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"