Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I would like to copy cells (after filling in) A4, B5, C6 and B3 into cells
F1, F2, F3 and F4 at the same time using a command button named Submit. After copied I want original cells A4,B5,C6,B3 empty again. Please help. Thanks |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
this works but is VERY clumsy....... there's got to be a better way,
probably using an array, but i don't know how to do it. ======================= Option Explicit Sub move() Dim r1 As Range Dim r2 As Range Dim r3 As Range Dim r4 As Range Set r1 = ActiveSheet.Range("a4") Set r2 = ActiveSheet.Range("b5") Set r3 = ActiveSheet.Range("c6") Set r4 = ActiveSheet.Range("b3") ActiveSheet.Range("f1").Value = r1.Value ActiveSheet.Range("f2").Value = r2.Value ActiveSheet.Range("f3").Value = r3.Value ActiveSheet.Range("f4").Value = r4.Value r1.ClearContents r2.ClearContents r3.ClearContents r4.ClearContents End Sub ================== hope somebody else posts with something better! :) susan On Jul 1, 12:46*pm, bgkgmg wrote: I would like to copy cells (after filling in) A4, B5, C6 and B3 into cells F1, F2, F3 and F4 at the same time using a command button named Submit. * After copied I want original cells A4,B5,C6,B3 empty again. *Please help.. Thanks |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
You could use this sub
Sub PickAndDrop() Dim ws As Worksheet Dim strSource(3) As String Dim strTarget(3) As String Dim i As Integer Set ws = ThisWorkbook.ActiveSheet strSource(0) = "A4" strSource(1) = "B5" strSource(2) = "C6" strSource(3) = "B3" strTarget(0) = "F1" strTarget(1) = "F2" strTarget(2) = "F3" strTarget(3) = "F4" For i = 0 To 3 ws.Range(strTarget(i)).Value = ws.Range(strSource(i)).Value ws.Range(strSource(i)).Clear Next i Set ws = Nothing End Sub -- Kevin Backmann "bgkgmg" wrote: I would like to copy cells (after filling in) A4, B5, C6 and B3 into cells F1, F2, F3 and F4 at the same time using a command button named Submit. After copied I want original cells A4,B5,C6,B3 empty again. Please help. Thanks |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
All you really need is this (if the Submit button is located on the same
sheet): Private Sub Submit_Click() Range("F1").Value = Range("A4").Value Range("F2").Value = Range("B5").Value Range("F3").Value = Range("C6").Value Range("F4").Value = Range("B3").Value Range("A4").Value = "" Range("B5").Value = "" Range("C6").Value = "" Range("B3").Value = "" End Sub Alan "bgkgmg" wrote: I would like to copy cells (after filling in) A4, B5, C6 and B3 into cells F1, F2, F3 and F4 at the same time using a command button named Submit. After copied I want original cells A4,B5,C6,B3 empty again. Please help. Thanks |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Try this...
Dim X As Long With Worksheets("Sheet3") For X = 0 To 3 .Range(Array("F1", "F2", "F3", "F4")(X)).Value = _ .Range(Array("A4", "B5", "C6", "B3")(X)).Value Next .Range("A4,B5,C6,B3").Clear End With Rick "bgkgmg" wrote in message ... I would like to copy cells (after filling in) A4, B5, C6 and B3 into cells F1, F2, F3 and F4 at the same time using a command button named Submit. After copied I want original cells A4,B5,C6,B3 empty again. Please help. Thanks |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Since you want the cells(A4,B5,C6,B3) copied after they are all have a value
you may want to add a safeguard that ensure the user has entered a value into all 4 of the cells. I would make this modification: Private Sub Submit_Click() Dim i As Byte Dim rng(3) As String rng(0) = "A4" rng(1) = "B5" rng(2) = "C6" rng(3) = "B3" 'tests cells to have a value in them For i = 0 To 3 If IsEmpty(Range(rng(i))) Then MsgBox "You must enter a value in Cell" & rng(i) & " to continue.", vbExclamation Exit Sub End If Next i 'copies range values Range("F1") = Range("A4") Range("F2") = Range("B5") Range("F3") = Range("C6") Range("F4") = Range("B3") 'clears range values For i = 0 To 3 Range(rng(i)) = "" Next i End Sub Hope this helps! If so please click "Yes" below. -- Cheers, Ryan "bgkgmg" wrote: I would like to copy cells (after filling in) A4, B5, C6 and B3 into cells F1, F2, F3 and F4 at the same time using a command button named Submit. After copied I want original cells A4,B5,C6,B3 empty again. Please help. Thanks |
#7
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
In the 3 posts that worked they all were erased when I clicked the Submit
button again. I want the info to remain in cells F1-F4 Thanks "bgkgmg" wrote: I would like to copy cells (after filling in) A4, B5, C6 and B3 into cells F1, F2, F3 and F4 at the same time using a command button named Submit. After copied I want original cells A4,B5,C6,B3 empty again. Please help. Thanks |
#8
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Try this:
Private Sub Submit_Click() If Not IsEmpty(ThisWorkbook.Sheets(Range("A4").Value) then Range("F1").Value = Range("A4").Value If Not IsEmpty(ThisWorkbook.Sheets(Range("B5").Value) then Range("F2").Value = Range("B5").Value If Not IsEmpty(ThisWorkbook.Sheets(Range("C6").Value) then Range("F3").Value = Range("C6").Value If Not IsEmpty(ThisWorkbook.Sheets(Range("B3").Value) then Range("F4").Value = Range("B3").Value Range("A4").Value = "" Range("B5").Value = "" Range("C6").Value = "" Range("B3").Value = "" End Sub On Jul 8, 1:38*am, bgkgmg wrote: In the 3 posts that worked they all were erased when I clicked the Submit button again. *I want the info to remain in cells F1-F4 Thanks "bgkgmg" wrote: I would like to copy cells (after filling in) A4, B5, C6 and B3 into cells F1, F2, F3 and F4 at the same time using a command button named Submit. * After copied I want original cells A4,B5,C6,B3 empty again. *Please help. Thanks |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Can't activate an add-ins | Setting up and Configuration of Excel | |||
activate VBA | Excel Programming | |||
activate VBA | Excel Programming | |||
Windows().Activate vs Workbooks().Activate | Excel Programming | |||
Workbook.Activate / Window.Activate problem | Excel Programming |