Wrox Programmer Forums
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 2nd, 2006, 02:11 AM
Authorized User
 
Join Date: Dec 2005
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to ggiibboo
Default Access to a cell

Would someone PLEASE be able to help me with this!!!!

I am trying to go through a spreadsheet and delete some unwanted data. I have created some if statements in order to determine which data should be deleted etc, however i want to dynamically change the rows that i test.

I have created a variable called starta and use this to store the row that i want to start my loop on. the problem i have is using this variable as part of a select statement.

starta = InputBox("please enter the starting row")

the select statement i have is:

atest = Range("A"&starta&":A"&starta).Value

if, for arguments sake, starta = 23, then i want atest to be like this:

atest = Range("A23:A23").Value

which would mean that atest holds the value of the cell A23

but when I try this line (the one in red) I keep getting an error.

Could someone please offer some assistance.

 
Old February 2nd, 2006, 03:26 AM
Registered User
 
Join Date: Oct 2005
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to ix_ly Send a message via MSN to ix_ly
Default

hey pal,

i think this code might be able to help you.


Public Sub deletingRow()
    Dim rowID As Long
    rowID = Application.InputBox(prompt:="Please enter a row number", Type:=1)
    Range("A1").Cells(rowID, "A").Value = ""
End Sub


ix
 
Old February 2nd, 2006, 09:22 PM
Authorized User
 
Join Date: Dec 2005
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to ggiibboo
Default

This doesn't really help. All this does is clear the contents of cell a<rownumber> however I have already worked out the code for deleting (removing) the rows that i don't want, I just want to be able to enter a number as the macro runs and that number will become part of a string. the string will be the argument for the function "Range" so that atest is now referring to a different row/cell.

any more suggestions?

 
Old February 2nd, 2006, 10:00 PM
Authorized User
 
Join Date: Dec 2005
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to ggiibboo
Default

I have almost sorted it out. It is a bit clumsy, but here is my solution, however there still remains a problem.

The solution i have is:

rowID = Application.InputBox(prompt:="Please enter a row number", Type:=1)

    arow = "A" & rowID
    brow = "A" & rowID + 1
    crow = "B" & rowID
    drow = "B" & rowID + 1

    atest = Range(arow).Value
    btest = Range(brow).Value
    ctest = Range(crow).Value
    dtest = Range(drow).Value


The problem remains when I try to delete the unwanted rows. I have used the following code:

delrows:

    rowIE = rowID + 1
    MsgBox ("Deletion of rows " & rowID & " & " & rowIE & " about to occur")
    Rows("rowID:rowIE").Select
    Selection.Delete Shift:=xlUp


however Excel throws up an error with the "rowID:rowIE" statement. this statement works if i put in actual numbers instead of variables, however I need to be able to put in variables as the argument to the Rows function.

in other words: Rows(2:3).Select works fine but Rows(rowID:rowIE).Select where rowID=2 and rowIE=3 doesn't work.

How to do this?


 
Old February 3rd, 2006, 01:47 AM
Authorized User
 
Join Date: Dec 2005
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to ggiibboo
Default

I've managed to sort it out. I was having trouble with the white spaces. I'm used to programming in C where whitespace isn't an issue, so i tried a couple of combos and found that the following worked fine:

Rows("" & rowID & ":" & rowIE).Select

 
Old February 3rd, 2006, 10:03 AM
Registered User
 
Join Date: Dec 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I had no trouble with just a few spaces in your original code, ie atest = Range("A" & starta & ":A" & starta).Value







Similar Threads
Thread Thread Starter Forum Replies Last Post
Export Access Data to a Specific Cell in Excel. VBNoob Access VBA 1 December 14th, 2005 08:25 PM
MS Access SQL: >1 querry results in one cell pav Access 0 November 23rd, 2004 06:14 AM
how to access cell of datagrid? basant ADO.NET 1 December 30th, 2003 02:01 PM
Access cell in DataGrid - wrong casting? drasko ASP.NET 1.0 and 1.1 Basics 4 December 22nd, 2003 04:45 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.