Quantcast
Channel: Excel Help Forum - Excel Programming / VBA / Macros
Viewing all 49987 articles
Browse latest View live

How to split numbers to specific name and total and split

$
0
0
How to split numbers to specific name and total and split

NAME TOTAL SPLIT SERIAL SERIAL FROM TO
X 200 2 A 1000 1999
Y 100 1 B 2000 2499
Z 400 4 C 3000 3499
D 5000 5999



I WANT RESULT RANDOM SELECT

NAME SERIAL FROM TO
X A 1050 1099
X C 3400 3449
Y C 3100 3149
Z A 1100 1149
Z B 2250 2299
Z C 3150 3200
Z D 5700 5749

Want new data in cell A1

$
0
0
I am running a macro where I get data from a website, however the actual link to the website changes every day because of the changing date.

The link is located in worksheet "one" and cell "A17"

So the macro is as follows:

Sheets("24hr to 9am").Select
Cells(1, 1).Select
With ActiveSheet.QueryTables.Add(Connection:= _
"URL;" & Range("One!A17").Value _
, Destination:=Range("$A$1"))
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlAllTables
.WebFormatting = xlWebFormattingNone
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
Sheets("Since 9am").Select

End Sub


-----------------------------------------------------------------

The result is data in 7 columns. The problem is that every time I run the macro the data gets pasted into every 8th column. I want the new data to always be pasted in cell A1. As you may see, I have tried to fix this by including "Cells(1, 1).Select" but this doesn't work. I would have thought "Destination:=Range("$A$1"))" would also mean the data always gets pasted in cell A1.

Would appreciate any help.

Replace multiple words from a Column

$
0
0
Replace multiple text in one command

Hi,
Wants to replace multiple words from string

For Exapmple in column C I have a Data which contains string

Date in column "C" as follows

"C2" =I have an Apple
"C3" =I have an Orange
"C4" =I have Mango
"C5" =I have Pineapple
"C6" =I will not give you my fruitsss


I want to replace

"an Apple" to "fruit"
"an Orange" to "fruit"
"Mango" to "fruit"
"Pineapple" to "fruit"
"Fruitsss" to "fruit"

So result should be as follows


"C2" =I have fruit
"C3" =I have fruit
"C4" =I have fruit
"C5" =I have fruit
"C6" =I will not give you my fruit

Please provide provision to add more words to replace

Automatic conditional formatting (color) for similar spreadsheets

$
0
0
Hey there, I'm a pretty big Excel noob so I hope I can explain what I need properly. This would help us out a lot at work!

So, basically, we run tests on a tasting panel of 10 three times a week. The software we use is called EyeQuestion and it spits out an Excel document that looks like this:

http://i.imgur.com/9hSBoEZ.png

What we then usually do is manually set up conditional formatting so we can easily see what numbers are in what cells. It's all based on the numbers of the products (as you can see each product has two codes in the screenshot, however they might have more - or less). We then print it out and use it to keep track of which products to serve when etc etc.

In the end it might look like this (which codes get which color doesn't matter, as long as they're all different):

http://i.imgur.com/Gikpjov.png

So, it takes quite a bit of time to manually assign a color for each of the codes it spits out. Is there a way of automating this? Maybe with a macro or something?

Appreciate all help greatly. :)

Find string in column in Sheet1, copy entire row to Sheet 2 and delete in Sheet 1

$
0
0
I started with
Code:

Sub CopyRows()
    Application.ScreenUpdating = False
    Dim bottomA As Integer
    bottomA = Sheets("Sheet1").Range("E" & Rows.Count).End(xlUp).Row
    Dim rng As Range
    For Each rng In Sheets("Sheet1").Range("E2:E" & bottomA)
        If rng = "Finished" Then
            rng.EntireRow.Copy Sheets("Sheet4").Cells(Rows.Count, "A").End(xlUp).Offset(1, 0)
        End If
    Next rng
    Application.CutCopyMode = False
End Sub

But cannot figure out to implement to delete rows in Sheet1 once they are copied.

word split

First blank row postion or the last nonblank row postiion in A columfrom a given row range

$
0
0
Hi all,

I am not very familiar with the VBA code, and I am a bit confused with how could i get the correct results from the below situation.

I got 3 lists of data, which they are arranged in 1 single column with a blank row (i.e. or a blank cell) to define them in 3 seperate list.

For example, if I set up list "A", from cell F22 to F28, list "B" from cell F31 to F32, and list "C" from cell F36 to F38.

My problem for the first issue is, how could i find the "row position" of the last nonblank cell of each list (i.e. codes can be seperated).

The second issue is the first blank cell for each list that I mentioned above.

What I have tried was some of the codes from previous threads such as:

Sub UnknownRange()
If WorksheetFunction.CountA(Cells) = 0 Then
MsgBox "There is no range to be selected.", , "No cells contain any values."
Exit Sub
Else
Dim FirstRow&, FirstCol&, LastRow&, LastCol&
Dim myUsedRange As Range
FirstRow = 22
On Error Resume Next
FirstCol = 6
If Err.Number <> 0 Then
Err.Clear
MsgBox _
"There are horizontally merged cells on the sheet" & vbCrLf & _
"that should be removed in order to locate the range.", 64, "Please unmerge all cells."
Exit Sub
End If

LastRow = Cells.Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row
LastCol = 6
Set myUsedRange = Range(Cells(FirstRow, FirstCol), Cells(LastRow, LastCol))
myUsedRange.Select
MsgBox "The data range on this worksheet is " & myUsedRange.Address(0, 0) & ".", 64, "Range address:"
End If
End Sub

But that doesn't seems to giving me the correct result as well.

Kindly advice me any insights or suggestions.

Many thanks!.

Geoven

Calculate percentage

$
0
0
Hi,

A beginner question here from a newbie. I have a document where I'm looking to know how many entries that isn't the number 0. It could be any other number, just not 0.

An example:

Entry 1:
Field A: Store 1
Field B: 0

Entry 2:
Field A: Store 1
Field B: 1

Entry 3:
Field A: Store 1
Field B: 27

Entry 4:
Field A: Store 2
Field B: 1

So I want a output here saying:
Store 2: 100%
Store 1: 66%

Thank you

add button and text box to a userform

$
0
0
Hello Chaps-- I have a userform already created called "Addclientform"
How do i add another command button,more text, and a textbox to this form??
Many thanks

fred
evans

How to scrape through the webpage that is opened in userform

$
0
0
Hi All,

I have work with Excel VBA for quite some time, but vary much new to web automation,
I have a user form in which a webpage is open, after user make certain selection, then I need to download the data
I am struck at this how to do it, if any one can help

Macro to replace formulas - sumif and buckets

$
0
0
Hi

I was previously helped with a post here: http://www.excelforum.com/excel-prog...-the-cell.html

Previously I had a working formula but I needed to run it using a macro as the using formula killed my machine as its 70k lines of data.

I was supplied a solution:

Code:

Sub test()
    Dim a, b, i As Long
    With Range("b2", Range("b" & Rows.Count).End(xlUp))
        a = .Value
        With .Offset(, 39)
            .ClearContents
            b = .Value
            With CreateObject("Scripting.Dictionary")
                For i = 1 To UBound(a, 1)
                    If (a(i, 1) <> "") * (Not .exists(a(i, 1))) Then
                        b(i, 1) = 1: .Item(a(i, 1)) = Empty
                    End If
                Next
            End With
            .Value = b
        End With
    End With
End Sub

The solution above works but I now need to add a sumif and aging buckets:
Cell AP: =IF(B2="","",IF(COUNTIF($B$2:B2,B2)=1,SUMIF($B$2:$B$71880,B2,$N$2:$N$71880),""))
Cell AQ: =LOOKUP(AP2, {0,501,1001,2001,3001,4001,5001,7501,10001}, {"0-500","501-1000","1001-2000","2001-3000","3001-4000","4001-5000","5001-7500","10000>"})
Cell AR: =LOOKUP(N2, {0,11,26,51,101,251,501,1001,10001}, {"0-10","11-25","26-50","51-100","101-250","251-500","501-1000","1000>"})

I thought I would be able to identify the previous solution formula but code is completely different

Any anyone help adding these three codes to the existing solution please?

Paul
Attached Files

Calling a module from another module

$
0
0
Sorry about this simple question, but I am a beginner. I can't figure out how to run another sub from another module. Here is what I have

Option Explicit

Sub AppendWorksheets()

Call Delete
Call Insert

End Sub


I have two other modules named Delete and Insert with one sub each that I want to run in this module. Thanks for any help in advance!

VBA code to set chart series to 'Automatic'

$
0
0
I'm wondering what the VBA code is to set the line format of a series to 'Automatic'. Basically, the VBA equivalent of manually selecting the 'Automatic' radio button in the "Format Data Series -> Line" menu. Is this even possible? All I get from the macro recorder is: "Selection.Format.Line.Visible = msoTrue" which doesn't do anything useful. I'm using Excel 2013.
Thanks!

Need Macro to FIND TEXT & Insert quotation marks

$
0
0
Hi, I'm new to this forum but have used your posts many times. Thanks to all!
I can't the solution that will resolve the following though, can you help?

My spread sheet has both alpha & numeric cells, going from A1 to G1040, including a few empty ones in between.

What I need is : in every cell that starts with either http, or https, then I want to insert a single quotation mark at the beginning of the text and at the end of the text. For example, I need for this : http://www.aircanada.com/en/travelin...age/index.html to become this : 'http://www.aircanada.com/en/travelinfo/airport/baggage/index.html'

I need the formula to loop to the end of the document.

Thanks

Chris

VBA macro to allocate persons to courses over periods - with restrictions...

$
0
0
I have a problem, and I think I best can solve it with a VBA code. So I really hope for some good ideas….....I try to explain

Basically i try to allocate persons to courses (groups) given a set of restrictions. The following just to give an example and explain the variables:

Persons 16 persons – named A to P
Team Each person is a member of a Team of 4 – Alfa, Beta, Delta, Gamma
Periods There are 8 periods - 2015 to 2022
Courses There are 8 courses - 1 to 8
Area Courses are subgrouped in areas (Corses 1, 2 and 3 as Area 1 etc.)

In reality the number of Persons and Teams may vary a lot. Periods and Courses will be more or less constant.

Restrictions (or conditions):

each person attend one course per year
each person must attend all 8 courses over the 8 periods
each course is followed by 2 persons, ie 8 courses with each 2 persons per period
persons from same team should not attend same course (or even better a counter/rule counts the number of case – and I can set a rule to iterate a new solution if the number is too high)
persons across teams should be mixed as much as possible (or like above – a counter/rule and iterate if there are too many)
a person should not attend courses in the same Area in successive years (the is nice to have, not need to)

It could be illustrated like this – each person gets a number 1 to 8 (in the rows), and each period (column) contains number 1 to 8 (2 of each)

https://dl.dropboxusercontent.com/u/12042084/Class.png


My thought is

first to allocate (more or less) randomly to the courses – but somehow aided so it doesn’t have to do loops over and over until the numbers fit (does this make sense??)
then define rules to check for the mixing of persons - and perhaps also teammembers in same course (if this can’t be handled in step 1)
depending on the rules in 2) it could accept the solution or reiterate (back to step 1)


Im so so VBA skilled, and the only way I can resolve step 1 is endless looping (I think), but im afraid that would affect handling time??

So any suggestions, please??

Best regards
Michael
Attached Images

I need some help creating new worksheets based on a list

$
0
0
So this code needs to look at a list on the first worksheet and create new worksheets based on that list, but only the new values. It works some of the time, but if there are no values in the list then I get an error message regarding the last If statement. Any help would be greatly appreciated!

Here is the code so far:

'Declare Variables
Dim bottomA As Long
Dim c2 As Range
Dim ws2 As Worksheet

'Set Range

bottomA = Range("A" & Rows.Count).End(xlUp).Row

'Loop through each value in range and create worksheet
For Each c2 In Range("A2:A" & bottomA)
Set ws2 = Nothing
On Error Resume Next
Set ws2 = Worksheets(c2.Value)
On Error GoTo 0
'set the name of the worksheet
If ws2 Is Nothing Then
Worksheets.Add(After:=Sheets(Sheets.Count)).Name = c.Value 'this is where the error message pops up
End If
Next c2

End Sub

I tried the new code but I am still getting an error message when there are no items on the list.

creating vba script to write semi complex formula across 1000+cells in 1 column

$
0
0
I'm entering the home stretch in my project, and the last piece is to tie the various figures together.

On my master sheet, I have my starting stock for products A and B for each customer and "today's count" which is calculated from here:

=SUM(F2+DAILY!$AF2+DAILY!$AF3+DAILY!$AF5+SUM(HISTORICAL!$F2:HISTORICAL!$BO3,HISTORICAL!$F5:$BO5))

This formula takes the starting stock, current regular and custom orders and new stock, historical regular and custom orders and new stock, adds
them all together and reports what we would currently have. Product B is calculated in a similar manner:

=SUM(F3+DAILY!$AF3+DAILY!$AF4+DAILY!$AF6+SUM(HISTORICAL!$F3:HISTORICAL!$BO3,HISTORICAL!$F6:$BO6))

The second customer's formula would be this for product A:

=SUM(F4+DAILY!$AF8+DAILY!$AF9+DAILY!$AF11+SUM(HISTORICAL!$F8:HISTORICAL!$BO9,HISTORICAL!$F11:$BO11))

Product B would be

=SUM(F5+DAILY!$AF10+DAILY!$AF12,HISTORICAL!$F10:HISTORICAL!$BO10,HISTORICAL!$F12:HISTORICAL!$BO12)

From what i've been able to learn so far (which is just enough to get in trouble :P) an array should help, but i don't really understand how to use them for something like this....

Evaluate with variable

$
0
0
I have:

Code:

last = Range("L" & Rows.Count).End(xlUp).Row
   
    Range("A1:A" & last).Value = Evaluate("Index(" & Mid(Range("B1:B" & last), 4, 20) & "),,1)")

However, it gives me a Run-time error '13': Type mismatch. I know it's the Range portion of the Evaluate formula, but how do I get the result I'm looking for (the last row variable is what's giving me trouble)?

Thanks

Drop down menu in User form

$
0
0
Please find the attachment.
In attachment I have created userform called "Details_of_Proposer"

First I need a vba code to call the form for data entry

second I need serial number to be automatially generated starting from one while entering the form detals

third I need drop down list in some fields of the form as given below

In Proposal field
Need options like 1) New Policy, 2) Renewal Policy, 3) Expired policy

In Select any one scheme field
Need options like 1) 2 years policy, 2) 5 years policy 3) 10 years polucy

In M/F field
Need options like 1) Male, 2) Female 3) Transgender

In Gender field
Need options like 1) Male, 2) Female 3) Transgender

In Mode of payment field
Need options like 1) Demand Draft, 2) Cheque 3) Online

Also I want all the data to be saved in Data sheet record wise (all Fields one after one)

Delete worksheets based on a list

$
0
0
Hi everyone, I am having trouble with my VBA code in one particular instance. I have this code that will delete any worksheet that is not specified on a list in the first workbook, and everything works fine except for when the list is empty. When the list is empty, I need all of the worksheets to be deleted except for the one with the list.

Here is the code:

Dim bottomA As Long
Dim c2 As Range
Dim ws2 As Worksheet

'Set Range

bottomA = Range("A" & Rows.Count).End(xlUp).Row

'Loop through each value in range and create worksheet
For Each c2 In Range("A2:A" & bottomA)
Set ws2 = Nothing
On Error Resume Next
Set ws2 = Worksheets(c2.Value)
On Error GoTo 0
'set the name of the worksheet

If ws2 Is Nothing Then
Worksheets.Add(After:=Sheets(Sheets.Count)).Name = c2.Value 'this is where the error message pops up
End If
Next c2

When it runs when there are no items on the list, it deletes all of the worksheets and keeps the one with the list, but it creates a new one and an error message pops up. Any help would be greatly appreciated!
Viewing all 49987 articles
Browse latest View live