Hi..
I want to copy the value of cell B21 (if not zero), to next empty cell in column B (after B26)and clear the cells B7:B8.
Pl. help me with a macro to do the above.
Thanks
Hi..
I want to copy the value of cell B21 (if not zero), to next empty cell in column B (after B26)and clear the cells B7:B8.
Pl. help me with a macro to do the above.
Thanks
Last edited by sarath25; 01-09-2011 at 04:48 AM.
How will you run the code?
![]()
If Cells(21, 2) <> 0 Then Cells(Rows.Count, 2).End(xlUp).Offset(1, 0).Value = Cells(21, 2) Range("B7:b8").ClearContents End If
Hope that helps.
RoyUK
--------
For Excel Tips & Solutions, free examples and tutorials why not check out my web site
Free DataBaseForm example
By assigning it as macro to a button.. Thanks
Then add the code that I gave to you to a button on the sheet
Did, but get an error "Compile error; Invalid outside procedure"
Pls. note, I have attached the sheet for u,
On clicking the save button,
I need the total value of B21 to be copied to the next empty row in after B26 and
entries in B7:B8 & B16:B20 to be cleared.
Thanks
Last edited by sarath25; 01-09-2011 at 04:49 AM.
Hello sarath25,
Welcome to the Forum!
The following macro has been added to "Save" button in the attached workbook.
![]()
Sub SaveData() Dim C As String Dim Cell As Range Dim EmptyCell As Range Dim Rng As Range Dim Wks As Worksheet C = "B" Set Wks = ActiveSheet Set Rng = Wks.Range(Wks.Cells(26, C), Wks.Cells(42, C)) For Each Cell In Rng If Cell = "" Then Set EmptyCell = Cell: Exit For Next Cell If EmptyCell Is Nothing Then MsgBox "There are No Empty Cells in Range " & Rng.Address Else EmptyCell.Value = Wks.Cells(21, C).Value Wks.Cells(7, C).Resize(2, 1).ClearContents Wks.Cells(16, C).Resize(5, 1).ClearContents End If End Sub
Sincerely,
Leith Ross
Remember To Do the Following....
1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.2. Thank those who have helped you by clicking the Starbelow the post.
3. Please mark your post [SOLVED] if it has been answered satisfactorily.
Old Scottish Proverb...
Luathaid gu deanamh maille! (Rushing causes delays!)
Thanks a lot dear, can an If condition added in the beginning to perform the macro only if B21 is not zero.
Just add this near the top:
![]()
C = "B" Set Wks = ActiveSheet If Wks.Range("B1") = 0 Then Exit Sub
_________________
Microsoft MVP 2010 - Excel
Visit: Jerry Beaucaire's Excel Files & Macros
If you've been given good help, use theicon below to give reputation feedback, it is appreciated.
Always put your code between code tags. [CODE] your code here [/CODE]
?None of us is as good as all of us? - Ray Kroc
?Actually, I *am* a rocket scientist.? - JB (little ones count!)
dOES THIS WORK?
![]()
Option Explicit Sub CopyData() If Cells(21, 2) <> 0 Then Cells(43, 2).End(xlUp).Offset(1, 0).Value = Cells(21, 2) Range("B7:b8,b16:b20").ClearContents End If End Sub
Thank you all for the kind help... I got it alright..
If you are satisfied with the solution(s) provided, please mark your thread as Solved.
How to mark a thread Solved
Go to the first post
Click edit
Click Go Advanced
Just below the word Title you will see a dropdown with the word No prefix.
Change to Solved
Click Save
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks