Incrementing Range Programmatically
Sep 20, 2006
I have the following function that looks at a range of data and deletes duplicate entries in each column. I want to change the range that is examined programmatically, rather than having to retype it for each range in this huge sheet! I have subtotaled and counted the rows in each range, so I know how many there are, but I'm stumped as to how to increment teh range correctly. I'm attaching a small sample of my data. The full sheet is 30,000+ rows and 94 columns.
Sub DelDups2()
Dim rngSrc As Range
Dim NumRows As Integer
Dim NumCols As Integer
Dim ThisRow As Integer
Dim ThatRow As Integer
Dim ThisCol As Integer
Dim J As Integer, K As Integer, x As Integer
Set rngSrc = ActiveSheet.Range("c68", "cr70")
NumCols = 94
NumRows = rngSrc.Rows.Count
ThisRow = rngSrc.Row
ThatRow = ThisRow + NumRows - 1
ThisCol = rngSrc.Column
For x = 1 To NumCols
For J = ThisRow To (ThatRow - 1)
If Cells(J, ThisCol) > "" Then................
View 2 Replies
ADVERTISEMENT
Jan 8, 2009
Programmatically UpdateNamed Range. Is it possibly to update a named range via VBA?
View 2 Replies
View Related
Aug 19, 2013
I have a workbook that contains a form with cells that use choice list validation. It also contains a worksheet with all the choice lists. Each choice list is a named range. The form is used to collect data that is new and from historical records. The historical records contain entries that are no longer allowed in new data. To allow for the older data I have choice lists (named ranges) that contain both the new and obsolete choices. This is a data problem waiting to happen. I would like to be able to have the user tell the workbook if the data is new or historical. If new I would only provide them with current choices. If historical, I would provide them with all choices, current and obsolete.
I would link the VBA script to change expand the ranges when told the data being entered is historical. The problem is I don't know how to code such a script. For example one of the cells has as current choices W, M, D. The range would be named MoistureState and the range would be A2:A4. There is one obsolete choice, E. If the Historical data button was clicked the MoistureState range would change from A2:A4 to A2:A5.
How would one go about expanding the named range?
View 8 Replies
View Related
Apr 15, 2014
I want to select a range of cells (not together I.e. b2, c3,c4,g7 etc) and copy them to another sheet but I need to check which cell has been selected as I am using a check box to set a cell as true or false if ticked or not, so if ticked a certain cell will be added to the selection set to be copied.
View 7 Replies
View Related
Mar 5, 2014
I have a piece of code that runs through multiple tables (they vary in length) and replacing values. All in the same worksheet
My code looks like this:
[Code] .....
How I get c to move to the next table and count the rows in that. In my code c stays constant, and I need it to change and match the new row count.
View 6 Replies
View Related
Jul 22, 2008
I have a spreadsheet which I need to remove all the blanks from, but instead of shifting cells up (I figured out how to do that in a macro), I want them to shift left.
I understand the basics of for...next loops etc, but I can't seem to understand how to make the selection in a range string variable. Not sure if this is a good explanation!
The code I have so far is....
View 10 Replies
View Related
Aug 20, 2014
following issue:
The following table is given:
flower
20
rose
flower
21
rose
[Code] ........
Which needs to be turned into:
flower
20
22
rose
flower
31
32
blossom
tree
1
3
apple
The last column is the one that dictates when a new range of numbers start. There should be one range of numbers for Rose, One range for Blossom etc.
View 4 Replies
View Related
Sep 15, 2012
Macro which will add a Listbox (Form control - not ActiveX) on each worksheet and give a sequential name to each ListBox.
View 5 Replies
View Related
Feb 10, 2013
The coding of the actual changes in the different modules is performing fine ...
But, I am stuck .. with two instructions : how to remove Add In password, and, how to set its IsAddIn property to false .
View 2 Replies
View Related
Feb 1, 2008
Until recently I successfully used this code to navigate to a web page and populate some of it's boxes, before programatically pressing the page's "Validate" button, whereupon the page would test the data I'd populated the boxes with, and come back with an answer to tell me if there were any errors in my data:
Private Sub CommandButton1_Click()
Dim uf1_cbutt1_click_ie As Object
Set uf1_cbutt1_click_ie = CreateObject("InternetExplorer.Application")
Can anyone shed any light on how I may be able to programatically navigate with VBA to the page I want? I'm also having trouble finding the new name of the "Validate" button - and how to programatically click it.
View 9 Replies
View Related
Jun 16, 2007
I have a VBA procedure that I need to be able to link/attach to an excel file which is created on the fly, and I need to do this programatically / on the fly. Basically, currently from my front end app, I output the necessary data to excel, and then format that data in excel using vba code sent through OLE to excel. Right after the formatting is done, I would like to then send the necessary vba commands to excel that would take my existing VBA sub routine, link it somehow to my excel file (by inserting it as a macro?, by registering/linking it as a .bas file?, any other options/ideas?), and then give the user a button or shortcut in the excel file that will run that VBA sub routine.
The underlined part above is my main goal here, and I already have the rest covered. I know there is more than one solution for this, but I would prefer a solution that allows me to store the vba code in the excel file itself, so that I only need to distribute the .xls file whenever I want to deploy this spreadsheet somewhere new.
View 2 Replies
View Related
Aug 7, 2007
Is it possible to lock/unlock the VBA code in a workbook through VBA from another workbook? I wish to copy modules from one workbook to another, both workbooks will have the VBA code password protected to stop prying eyes. Obviously I need to unlock the VBA in the target workbook before the copy and lock it again afterwards. Can this be done programatically? If there is no function in VBA to do this can you provide an example of how to do it using SendKeys if that is the only way to do it?
View 3 Replies
View Related
Jan 31, 2014
I want to use script to programmatically create Hyperlink in multiple cells. The Hyperlink will trigger a macro event and run a simple command using the "PC Name" as input variable. The Hyperlink should have:
-Text to display: - different "PC Name" in each cell
-Type the cell reference: - corresponding to the cell where the Hyperlink is inserted
-Link to: - Place in This Document
I tried using cell formula, but it always default to "Existing File or Web Page".
ExcelHyperlink.png
View 2 Replies
View Related
Feb 14, 2014
I have an expanding worksheet and would like to move a button so that it is always near the bottom of the worksheet data. When the button is pressed it reworks the worksheet and adds in some additional rows (up to 10 max). I'd like it so that the procedure also moves the button down keeping it in line with approximately the last row of data but not sure how to do this with vba...
View 4 Replies
View Related
Feb 16, 2005
Trying to select multiple shapes based on shape properties. The missing piece is the code to select the shapes. The examples in the help use the 'Array' function with a list of shape names.
Is there a way to select a random set of shapes without using the Array function?
Or how does one build a list for use with the Array function?
View 10 Replies
View Related
Jan 11, 2010
I'm trying to programmatically add and remove the Outlook 11.0 Reference Library in Excel 2003. So far, I have found the following code which successfuly adds the reference:
View 3 Replies
View Related
Jan 4, 2013
To refresh a UserForm ListBox when new items are added, I Unload and Show the Userform as part of the procedure.
Code:
Private Sub CommandButton4_Click()
'do stuff
'do some more stuff
'do a few more things
'finish doing stuff
Unload Me
UserForm2.Show
This returns the UserForm to its Initialized state and displays the refreshed list.
But, this requires the user to click CommandButton6 to continue adding additional items. If CommandButton4 code could click CommandButton6, the UserForm would Show in its "add item" state...I think. Is there a way to programmatically click a CommandButton?
I've already tried 8,321 ways without success...(OK, maybe only 4 ways)
View 9 Replies
View Related
Jan 7, 2014
What I have is a list of data on a sheet. Through some code, I would like to visualize my data in a certain way. What I currently have is a grid, each square corresponding to a single data point. I would like to assign a tooltip to a label that will be sitting on top each of these squares.
What I have so far: I have a userform which will be populated by labels programmatically. I am doing it like this because there are at least a few thousand labels to be created. I am currently doing it like this:
Code:
counter = 15
For i = 1 To 20
For j = 1 To numrows
[Code]....
Essentially, what I have is a grid, and I would like to change the letter "x" in the label to another color when the mouse is hovering over the label.
Is this the correct way of achieving what I want, or is there a better way? Is there a way of assigning a single mouseover/hover event to the label once it has been created? (All these labels can be handled by a single function to just change the text color).
View 1 Replies
View Related
May 19, 2014
I am trying to create a table (listobject) from a textfile datasource on a shared drive.
How to get this over the line, I have the following code which I am struggling to finish.
Code:
Sub Testing
Dim wb As Workbook
Dim ws As Worksheet
Dim ws2 As Worksheet
Dim lo As ListObject
Const Pathway As String = "F:Scripting"
Const File As String = "Log.txt"
[code]....
View 1 Replies
View Related
Aug 19, 2009
I have a suite of subroutines and functions stored in an .xla file, which other users have access to. It's installed on the local machine via macro which installs a user defined menu to access them from. Howerver, when an XL chart worksheet is active, this menu doesn't appear and there are a couple of functions where it would be useful to have access to when viewing such a chart. I've noticed user defined toolbar icons are available in this view, so would like to use these to access the relevant routines. I know you can insert them in code (macro recorder) but is it possible to assign macros to them from the same code? Alternatively, is it possible to show my user defined menu in chart sheets as well as normal worksheets?
View 9 Replies
View Related
Nov 17, 2009
Suppose I have a userform named myUserForm and a checkbox on it named myCheckBox. How on earth do I remove myCheckBox from myUserForm at run time? I've tried every which way I can think and I always get "error 444". Some things I've tried are:
myUserForm.Controls.Remove "myCheckBox"
myUserForm.Controls.Remove(myCheckBox)
myUserForm.Controls("myCheckBox").Remove
myUserForm.Controls.RemoveControls "myCheckBox"
I've put this in a standard module, the ThisWorkbook module, even in the myUserForm code module and each time it's the same error.
View 9 Replies
View Related
Feb 16, 2013
I have a very complex report with a variable numbers of rows in multiple sections. I am evaluating whether to display each row with a formula in the first column (those that I don't want to display have a "H" in the first column).
The following code works fine, but it takes forever. Ideally I wanted to trigger the code on the Worksheet_Activate() event but its so inefficient that I can't do that.
VB:
On Error Goto Errorhandling
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Application.EnableEvents = False
Application.Calculation = xlManual
Application.StatusBar = "Processing..."
[Code] .....
View 4 Replies
View Related
Nov 7, 2011
I have wirtten a sub routine that builds a userForm dynamically based on user specific data. The form builds just fine and 9 times out of 10 the code at the end of the sub routine removes the form from the workbook. Since it's built on the fly I don't bother renaming the form. The times when it does not remove itself and the user restarts the program, part of the code written to the forms module references "UserForm1". and the the code halts. I know there is a way I can verify that UserForm1 has been removed and if not remove it before executing the next sub routine, I'm just tired and can't remember anything. Note that the UserForm1 contains CommandButtons that direct the user to Static UserForms that do not get removed, and those can trigger the sub routine to rebuild the dynamic UserForm.
View 3 Replies
View Related
Jul 25, 2013
I have both Excel 2003 and Excel 2007 installed on my computer, using VBA code is it possible to specify which version I open an excel document in?
View 2 Replies
View Related
Nov 9, 2009
I'm trying to insert a worksheet change event using VBA. I have this sample code from here -
http://www.cpearson.com/Excel/vbe.aspx
Sub CreateEventProcedure()
Dim VBProj As VBIDE.VBProject
Dim VBComp As VBIDE.VBComponent
Dim CodeMod As VBIDE.CodeModule
Dim LineNum As Long
Const DQUOTE = """" ' one " character
Set VBProj = ActiveWorkbook.VBProject
Set VBComp = VBProj.VBComponents("ThisWorkbook")
Set CodeMod = VBComp.CodeModule...................
View 9 Replies
View Related
Apr 2, 2008
I created a macro to create command buttons on sheet 1 of my worksheet. The created buttons using oleobject and class type: forms.commandbutton1, creates an object with no properties on the sheet (i.e. if you right click on it excel thinks it's an object and not a control.) Is there a way to create it as a control?
View 4 Replies
View Related
Dec 19, 2013
So I have a bunch of not so simple excel sheets in a Excel file. I'm trying to automate the testing of these (right now, I'm doing the testing manually).
To simplify, let's say there are two sheets - both of them have a cell called "Total" at the end, which is nothing much a total of some column. My test is to check if these two totals are the same. We don't know the number of rows before hand (it is coming from a database). The way I'm doing right now, is searching for the cell containing the text "Total" getting it's row and column, and adding 1 to the column, to get the cell that actually has the total value. Do this for both the sheets, and I have both values, and it's easy to compare now.
If someone changes the text from "Total" to "Totals" then this will fail.
Questions:
1. Is there a better way to do this? Say, setting a unique parameter or something on the cell that actually has the total value, and using that unique parameter to search the cell?
2. Or is there a totally different (better) approach to this type of testing?
View 6 Replies
View Related
Jun 19, 2009
i m working on an excel 2007 workbook with ms project functionality. in order to be able to use ms project from within excel i m using early binding. for those who dont know what early binding is: http://www.dicks-clicks.com/excel/olBinding.htm
this works fine if the user has ms project installed on his/her pc.
if the user does not have ms project installed i remove the broken references. this works fine.
but my problem is that when i remove the reference to ms project, my vba project will not compile correctly. thus each time when a user opens the workbook the user gets a "compile error in hidden module" , since the functions of ms project are not available.
for example i get a compile error in the following source
Public Function getResID(ResName As String, ActiveProject As Project) As Integer
Dim res As Resource
For Each res In ActiveProject.Resources
If res.name = ResName Then
getResID = res.ID
Exit Function
End If
getResID = -1
Next
End Function
i just want to know what i can do to prevent the compile error? would the use of late binding remove the problem? actually i dont want to use late binding since my source code is already very complex and it would be a huge effort to change it.
View 9 Replies
View Related
Nov 24, 2008
Im trying to create a catalogue for our complaints that come in each day at work. Ive created a basic layout I like, it uses 3 cells for a week day and 1 cell for a weekend day. The date is listed on the side of each day. I would now like to be able to quickly use this format for the rest of the month/year but need a way to do this easily as I cant do each day separately in the future. Ive tried selecting cells and then dragging down but all it does is repeat the previous 7 days and the same dates instead of incrementing the date.
Ive attached an image ...
View 2 Replies
View Related
Jan 10, 2010
Im using the following HLOOKUP formula : =HLOOKUP($B$14,$DA$15:$EH$380,2,FALSE) and I need to drag it down 365 times, but the row index num, ie ‘2’ does not increment with the drag. Is this correct – or is there a way of making the 2 increment?
View 3 Replies
View Related