PC Review


Reply
Thread Tools Rate Thread

Button - Macro to auto-populate data

 
 
dcarter
Guest
Posts: n/a
 
      29th Nov 2007
I am trying to create two buttons that, when either is selected, will run a
macro to populate all fields in that column with a "Yes" or "No" depending on
what button they clicked on. Let's say the "Yes" button is placed in cell
A1, and, if selected, all fields from A2 on have "Yes" inputted. I would
also like the macro to look at Column B. If the contents of cell B2 are
blank, then A2 would remain blank. If cell B3 has something in it, then A3
would populate with a "Yes" after the "Yes" button is selected.

I know how to create the buttons, but I am having trouble completing the
macro. Any help you could provide would be greatly appreciated. Thanks!
 
Reply With Quote
 
 
 
 
DomThePom
Guest
Posts: n/a
 
      29th Nov 2007
Here is a sub that does what you need - copy the code into a standard module
and run the sub fom the click event of your buttons, using "Yes" abd "No" as
parameters, as appropriate
Note that I have assumed that there is nothing else on your sheet apart from
what you have described in columns A and B - if this is not the case then you
will have to redefine the range rng below.
There are clearly many ways that your requirement could be met but I think
using the autofilter provides the most elegant solution

****************************************
Start code
****************************************
Sub DoFill(ByVal txtType As String)
Dim rng As Range
'turn off screen
Application.ScreenUpdating = False
'define the right hand column of the range (B1 to the last used cell)
Set rng = Range(ActiveSheet.Cells(1, 2), _
ActiveSheet.UsedRange.SpecialCells(xlCellTypeLastCell))
With rng
'filter the range to non-blanks
.AutoFilter Field:=1, Criteria1:="<>"
'fill the visible cells 1 column to the left with the parameter
.Offset(1, -1).Resize(rng.Rows.Count - 1). _
SpecialCells(xlCellTypeVisible).Value = txtType
'clear the autofilter
.AutoFilter
End With
Application.ScreenUpdating = True
Set rng = Nothing
End Sub

**************************************
End of Code
**************************************

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Need Cmd Button to add new record and auto populate fields tina Microsoft Access 6 23rd Apr 2009 07:58 PM
Re: Need Cmd Button to add new record and auto populate fields Clif McIrvin Microsoft Access 5 15th Apr 2009 02:10 PM
Re: Need Cmd Button to add new record and auto populate fields John W. Vinson Microsoft Access 0 10th Apr 2009 09:02 PM
Auto populate w/click of a 'button' Shanen Microsoft Excel Misc 6 28th Apr 2008 08:15 PM
Can a macro - auto populate sheets... =?Utf-8?B?ZHJpbGxlcg==?= Microsoft Excel Misc 4 5th Jul 2007 09:54 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:44 PM.